diff --git a/examples/nested-routes/app.js b/examples/nested-routes/app.js index 420389275..1d3b011ac 100644 --- a/examples/nested-routes/app.js +++ b/examples/nested-routes/app.js @@ -36,15 +36,22 @@ const Quy = { ` } -const Quux = { template: '
quux
' } -const Zap = { template: '

zap

{{ $route.params.zapId }}
' } +const Quux = { + template: `
quuxgo to quuy
` +} +const Quuy = { template: '
quuy
' } +const Zap = { + template: '

zap

{{ $route.params.zapId }}
' +} const router = new VueRouter({ mode: 'history', base: __dirname, routes: [ { path: '/', redirect: '/parent' }, - { path: '/parent', component: Parent, + { + path: '/parent', + component: Parent, children: [ // an empty path will be treated as the default, e.g. // components rendered at /parent: Root -> Parent -> Default @@ -65,7 +72,10 @@ const router = new VueRouter({ { path: 'qux/:quxId', component: Qux, - children: [{ path: 'quux', name: 'quux', component: Quux }] + children: [ + { path: 'quux', name: 'quux', component: Quux }, + { path: 'quuy', name: 'quuy', component: Quuy } + ] }, { path: 'quy/:quyId', component: Quy }, @@ -91,6 +101,8 @@ new Vue({
  • /parent/zap
  • /parent/zap/1
  • { params: { zapId: 2 }} (relative params)
  • +
  • /parent/qux/1/quux
  • +
  • /parent/qux/2/quux
  • diff --git a/src/util/location.js b/src/util/location.js index 364e6fc0c..176b50141 100644 --- a/src/util/location.js +++ b/src/util/location.js @@ -15,8 +15,10 @@ export function normalizeLocation ( ): Location { let next: Location = typeof raw === 'string' ? { path: raw } : raw // named target - if (next.name || next._normalized) { + if (next._normalized) { return next + } else if (next.name) { + return extend({}, raw) } // relative params diff --git a/test/e2e/specs/nested-routes.js b/test/e2e/specs/nested-routes.js index e5a8f16a1..ef52a251d 100644 --- a/test/e2e/specs/nested-routes.js +++ b/test/e2e/specs/nested-routes.js @@ -3,7 +3,7 @@ module.exports = { browser .url('http://localhost:8080/nested-routes/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 9) + .assert.count('li a', 11) .assert.urlEquals('http://localhost:8080/nested-routes/parent') .assert.containsText('.view', 'Parent') .assert.containsText('.view', 'default') @@ -70,6 +70,13 @@ module.exports = { return (zapId === '2') }, null, 'relative params') + .click('li:nth-child(10) a') + .assert.urlEquals('http://localhost:8080/nested-routes/parent/qux/1/quux') + .click('li:nth-child(11) a') + .assert.urlEquals('http://localhost:8080/nested-routes/parent/qux/2/quux') + .click('.nested-child a') + .assert.urlEquals('http://localhost:8080/nested-routes/parent/qux/2/quuy') + // check initial visit .url('http://localhost:8080/nested-routes/parent/foo') .waitForElementVisible('#app', 1000) diff --git a/test/unit/specs/location.spec.js b/test/unit/specs/location.spec.js index 0b44bae9e..e333421b1 100644 --- a/test/unit/specs/location.spec.js +++ b/test/unit/specs/location.spec.js @@ -120,5 +120,14 @@ describe('Location utils', () => { const loc2 = normalizeLocation(loc1) expect(loc1).toBe(loc2) }) + + it('creates copies when not normalized', () => { + const l1 = { name: 'foo' } + expect(normalizeLocation(l1)).not.toBe(l1) + const l2 = { path: '/foo' } + expect(normalizeLocation(l2)).not.toBe(l2) + const l3 = { path: '/foo', query: { foo: 'foo' }} + expect(normalizeLocation(l3)).not.toBe(l3) + }) }) })