Skip to content
This repository was archived by the owner on Mar 1, 2020. It is now read-only.

Add custom history support through mode #1

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ function genConfig (opts) {
format: opts.format,
banner,
name: 'VueRouter'
},
watch: {
chokidar: false
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ export default class VueRouter {
this.afterHooks = []
this.matcher = createMatcher(options.routes || [], this)

let CustomHistory
let mode = options.mode || 'hash'
this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false
if (this.fallback) {
mode = 'hash'
}
if (!inBrowser) {

if (options.mode && options.mode.constructor === Object) {
mode = options.mode.name

CustomHistory = options.mode.factory(AbstractHistory)
}

if (!inBrowser && !CustomHistory) {
mode = 'abstract'
}
this.mode = mode
Expand All @@ -62,6 +70,11 @@ export default class VueRouter {
this.history = new AbstractHistory(this, options.base)
break
default:
if (CustomHistory) {
this.history = new CustomHistory(this, options.base)
break
}

if (process.env.NODE_ENV !== 'production') {
assert(false, `invalid mode: ${mode}`)
}
Expand Down