File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 1- const internalKeysRE = / ^ ( c o m p o n e n t | s u b R o u t e s ) $ /
1+ const internalKeysRE = / ^ ( c o m p o n e n t | s u b R o u t e s | n a m e | f u l l P a t h ) $ /
22
33/**
44 * Route Context Object
Original file line number Diff line number Diff line change @@ -80,14 +80,28 @@ export default function (Vue, Router) {
8080
8181 /**
8282 * Navigate to a given path.
83+ * The path can be an object describing a named path in
84+ * the format of { name: '...', params: {}, query: {}}
8385 * The path is assumed to be already decoded, and will
8486 * be resolved against root (if provided)
8587 *
86- * @param {String } path
88+ * @param {String|Object } path
8789 * @param {Boolean } [replace]
8890 */
8991
9092 Router . prototype . go = function ( path , replace ) {
93+ // handle named routes
94+ if ( typeof path === 'object' ) {
95+ if ( path . name ) {
96+ var params = path . params || { }
97+ if ( path . query ) {
98+ params . queryParams = path . query
99+ }
100+ path = this . _recognizer . generate ( path . name , params )
101+ } else if ( path . path ) {
102+ path = path . path
103+ }
104+ }
91105 this . history . go ( path + '' , replace )
92106 }
93107
Original file line number Diff line number Diff line change @@ -22,7 +22,10 @@ export default function (Vue, Router) {
2222 path : path ,
2323 handler : handler
2424 } )
25- this . _recognizer . add ( segments )
25+ this . _recognizer . add ( segments , {
26+ as : handler . name
27+ } )
28+ // add sub routes
2629 if ( handler . subRoutes ) {
2730 for ( let subPath in handler . subRoutes ) {
2831 // recursively walk all sub routes
You can’t perform that action at this time.
0 commit comments