From 16961162b3bfa20e352a00a708f36641a7552b3b Mon Sep 17 00:00:00 2001 From: Ricky Boyce Date: Wed, 9 Oct 2019 23:50:11 +1300 Subject: [PATCH 1/3] feat(history): allow same route navigation --- src/history/base.js | 17 ++++++----------- test/e2e/specs/navigation-guards.js | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index 2b12e1967..ea931199a 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -5,7 +5,7 @@ import type Router from '../index' import { inBrowser } from '../util/dom' import { runQueue } from '../util/async' import { warn, isError, isExtendedError } from '../util/warn' -import { START, isSameRoute } from '../util/route' +import { START } from '../util/route' import { flatten, flatMapComponents, @@ -116,14 +116,6 @@ export class History { } onAbort && onAbort(err) } - if ( - isSameRoute(route, current) && - // in the case the route map has been dynamically appended to - route.matched.length === current.matched.length - ) { - this.ensureURL() - return abort(new NavigationDuplicated(route)) - } const { updated, deactivated, activated } = resolveQueue( this.current.matched, @@ -240,15 +232,18 @@ function resolveQueue ( } { let i const max = Math.max(current.length, next.length) + + // Get the index of the first non-matching route pair for (i = 0; i < max; i++) { if (current[i] !== next[i]) { break } } + return { updated: next.slice(0, i), - activated: next.slice(i), - deactivated: current.slice(i) + activated: next, + deactivated: current } } diff --git a/test/e2e/specs/navigation-guards.js b/test/e2e/specs/navigation-guards.js index 857035dee..2ac12e37d 100644 --- a/test/e2e/specs/navigation-guards.js +++ b/test/e2e/specs/navigation-guards.js @@ -150,7 +150,7 @@ module.exports = { .assert.containsText('#bre-order', 'parent mixin child 2') .click('#nested-parent a') .assert.urlEquals('http://localhost:8080/navigation-guards/parent/child/1') - .assert.containsText('#bre-order', 'parent mixin child 2 mixin child 1') + .assert.containsText('#bre-order', 'parent mixin child 2 parent mixin child 1') .end() } } From e76a2213f5372890a38c611891f427b77a95b20a Mon Sep 17 00:00:00 2001 From: Ricky Boyce Date: Fri, 11 Oct 2019 00:26:07 +1300 Subject: [PATCH 2/3] fix(history): use replace instead of push for same routes --- src/history/hash.js | 29 +++++++++++------------------ src/history/html5.js | 3 ++- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/history/hash.js b/src/history/hash.js index 25a670fcb..19d963f6f 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -49,28 +49,21 @@ export class HashHistory extends History { push (location: RawLocation, onComplete?: Function, onAbort?: Function) { const { current: fromRoute } = this - this.transitionTo( - location, - route => { - pushHash(route.fullPath) - handleScroll(this.router, route, fromRoute, false) - onComplete && onComplete(route) - }, - onAbort - ) + this.transitionTo(location, route => { + const fn = fromRoute.fullPath === route.fullPath ? replaceHash : pushHash + fn(route.fullPath) + handleScroll(this.router, route, fromRoute, false) + onComplete && onComplete(route) + }, onAbort) } replace (location: RawLocation, onComplete?: Function, onAbort?: Function) { const { current: fromRoute } = this - this.transitionTo( - location, - route => { - replaceHash(route.fullPath) - handleScroll(this.router, route, fromRoute, false) - onComplete && onComplete(route) - }, - onAbort - ) + this.transitionTo(location, route => { + replaceHash(route.fullPath) + handleScroll(this.router, route, fromRoute, false) + onComplete && onComplete(route) + }, onAbort) } go (n: number) { diff --git a/src/history/html5.js b/src/history/html5.js index e1cdba97d..09274cf74 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -44,7 +44,8 @@ export class HTML5History extends History { push (location: RawLocation, onComplete?: Function, onAbort?: Function) { const { current: fromRoute } = this this.transitionTo(location, route => { - pushState(cleanPath(this.base + route.fullPath)) + const fn = fromRoute.fullPath === route.fullPath ? replaceState : pushState + fn(cleanPath(this.base + route.fullPath)) handleScroll(this.router, route, fromRoute, false) onComplete && onComplete(route) }, onAbort) From fe2ff8c0623ebde9c84c86186d905abc48fb8555 Mon Sep 17 00:00:00 2001 From: Ricky Boyce Date: Tue, 22 Oct 2019 14:56:04 +1300 Subject: [PATCH 3/3] fix(route): unique components on reload via `home' } +const Home = { template: '
home
', data: () => { console.log('data reprocessed'); return {} } } const Foo = { template: '
foo
' } const Bar = { template: '
bar
' } const Unicode = { template: '
unicode
' } @@ -53,7 +53,7 @@ new Vue({
{{ n }}
{{ $route.query.t }}
{{ $route.hash }}
- + `, diff --git a/src/util/route.js b/src/util/route.js index 54a91a738..66f584f75 100644 --- a/src/util/route.js +++ b/src/util/route.js @@ -19,6 +19,7 @@ export function createRoute ( } catch (e) {} const route: Route = { + id: Date.now(), name: location.name || (record && record.name), meta: (record && record.meta) || {}, path: location.path || '/',