11import { warn } from './util'
2- import Router from './router'
3-
2+ import Recognizer from 'route-recognizer'
43import RouterApi from './router/api'
54import RouterInternal from './router/internal'
65import View from './directives/view'
76import Link from './directives/link'
87import Override from './override'
8+ import AbstractHistory from './history/abstract'
9+ import HashHistory from './history/hash'
10+ import HTML5History from './history/html5'
11+
12+ const historyBackends = {
13+ abstract : AbstractHistory ,
14+ hash : HashHistory ,
15+ html5 : HTML5History
16+ }
17+
18+ /**
19+ * Router constructor
20+ *
21+ * @param {Object } [options]
22+ */
23+
24+ export default class Router {
25+
26+ constructor ( {
27+ hashbang = true ,
28+ abstract = false ,
29+ history = false ,
30+ saveScrollPosition = false ,
31+ transitionOnLoad = false ,
32+ suppressTransitionError = false ,
33+ root = null ,
34+ linkActiveClass = 'v-link-active'
35+ } = { } ) {
36+
37+ /* istanbul ignore if */
38+ if ( ! Router . installed ) {
39+ throw new Error (
40+ 'Please install the Router with Vue.use() before ' +
41+ 'creating an instance.'
42+ )
43+ }
44+
45+ // Vue instances
46+ this . app = null
47+ this . _views = [ ]
48+ this . _children = [ ]
49+
50+ // route recognizer
51+ this . _recognizer = new Recognizer ( )
52+ this . _guardRecognizer = new Recognizer ( )
53+
54+ // state
55+ this . _started = false
56+ this . _currentRoute = { }
57+ this . _currentTransition = null
58+ this . _previousTransition = null
59+ this . _notFoundHandler = null
60+ this . _beforeEachHook = null
61+ this . _afterEachHook = null
62+
63+ // feature detection
64+ this . _hasPushState =
65+ typeof window !== 'undefined' &&
66+ window . history &&
67+ window . history . pushState
68+
69+ // trigger transition on initial render?
70+ this . _rendered = false
71+ this . _transitionOnLoad = transitionOnLoad
72+
73+ // history mode
74+ this . _abstract = abstract
75+ this . _hashbang = hashbang
76+ this . _history = this . _hasPushState && history
77+
78+ // other options
79+ this . _saveScrollPosition = saveScrollPosition
80+ this . _linkActiveClass = linkActiveClass
81+ this . _suppress = suppressTransitionError
82+
83+ // create history object
84+ let inBrowser = Router . Vue . util . inBrowser
85+ this . mode = ( ! inBrowser || this . _abstract )
86+ ? 'abstract'
87+ : this . _history
88+ ? 'html5'
89+ : 'hash'
90+
91+ let History = historyBackends [ this . mode ]
92+ let self = this
93+ this . history = new History ( {
94+ root : root ,
95+ hashbang : this . _hashbang ,
96+ onChange : function ( path , state , anchor ) {
97+ self . _match ( path , state , anchor )
98+ }
99+ } )
100+ }
101+ }
102+
103+ Router . installed = false
9104
10105/**
11106 * Installation interface.
@@ -32,5 +127,3 @@ Router.install = function (Vue) {
32127if ( typeof window !== 'undefined' && window . Vue ) {
33128 window . Vue . use ( Router )
34129}
35-
36- export default Router
0 commit comments