Skip to content

Commit

Permalink
feat: allow to configure router mode
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Nov 19, 2018
1 parent 9193c66 commit 969ea5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {sync} from 'vuex-router-sync'
import PluginAPI from './PluginAPI'
import Root from './components/Root.vue'
import store from './store'
import router from './router'
import createRouter from './router'
import alternativeComponents from './utils/alternativeComponents'
import ImageZoom from './components/ImageZoom.vue'
import Badge from './components/Badge.vue'
Expand All @@ -13,8 +13,6 @@ import i18nPlugin from './plugins/i18n'
import evaluateContentPlugin from './plugins/evaluateContent'
import versionsPlugin from './plugins/versions'

sync(store, router)

Vue.component(ImageZoom.name, ImageZoom)
Vue.component(Badge.name, Badge)
Vue.use(alternativeComponents)
Expand All @@ -30,6 +28,9 @@ Vue.mixin({

class Docute {
constructor(config = {}) {
const router = createRouter({routerMode: config.routerMode})
sync(store, router)

store.commit('SET_ORIGINAL_CONFIG', {
title: document.title,
...config
Expand Down
30 changes: 15 additions & 15 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import Home from './views/Home.vue'

Vue.use(Router)

const router = new Router({
routes: [
{
path: '*',
component: Home
export default ({routerMode}) =>
new Router({
mode: routerMode,
routes: [
{
path: '*',
component: Home
}
],
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
return {x: 0, y: 0}
}
],
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
return {x: 0, y: 0}
}
})

export default router
})

0 comments on commit 969ea5e

Please sign in to comment.