22
33import { install } from './install'
44import { createMatcher } from './create-matcher'
5- import { HashHistory , getHash } from './history/hash'
6- import { HTML5History , getLocation } from './history/html5'
5+ import { HashHistory } from './history/hash'
6+ import { HTML5History } from './history/html5'
77import { AbstractHistory } from './history/abstract'
88import { inBrowser , supportsHistory } from './util/dom'
99import { assert } from './util/warn'
1010import { cleanPath } from './util/path'
1111import { normalizeLocation } from './util/location'
12+ import { START } from './util/route'
1213
1314export default class VueRouter {
1415 static install : ( ) => void ;
@@ -51,7 +52,9 @@ export default class VueRouter {
5152 this . history = new AbstractHistory ( this , options . base )
5253 break
5354 default :
54- process . env . NODE_ENV !== 'production' && assert ( false , `invalid mode: ${ mode } ` )
55+ if ( process . env . NODE_ENV !== 'production' ) {
56+ assert ( false , `invalid mode: ${ mode } ` )
57+ }
5558 }
5659 }
5760
@@ -71,14 +74,18 @@ export default class VueRouter {
7174 const history = this . history
7275
7376 if ( history instanceof HTML5History ) {
74- history . transitionTo ( getLocation ( history . base ) )
77+ history . transitionTo ( history . getCurrentLocation ( ) )
7578 } else if ( history instanceof HashHistory ) {
7679 const setupHashListener = ( ) => {
7780 window . addEventListener ( 'hashchange' , ( ) => {
7881 history . onHashChange ( )
7982 } )
8083 }
81- history . transitionTo ( getHash ( ) , setupHashListener , setupHashListener )
84+ history . transitionTo (
85+ history . getCurrentLocation ( ) ,
86+ setupHashListener ,
87+ setupHashListener
88+ )
8289 }
8390
8491 history . listen ( route => {
@@ -148,6 +155,14 @@ export default class VueRouter {
148155 href
149156 }
150157 }
158+
159+ addRoutes ( routes : Array < RouteConfig > ) {
160+ routes = this . options . routes = ( this . options . routes || [ ] ) . concat ( routes )
161+ this . match = createMatcher ( routes )
162+ if ( this . history . current !== START ) {
163+ this . history . transitionTo ( this . history . getCurrentLocation ( ) )
164+ }
165+ }
151166}
152167
153168function createHref ( base : string , fullPath : string , mode ) {
0 commit comments