From 0c238c4f08225783811ae4710b86533ca1d44c14 Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Tue, 19 Jun 2018 10:44:20 +0200 Subject: [PATCH 1/6] Fix hash mode deep links --- src/history/hash.js | 15 +++++++++------ src/index.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/history/hash.js b/src/history/hash.js index 330f2383c..bd2018945 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -8,10 +8,10 @@ import { setupScroll, handleScroll } from '../util/scroll' import { pushState, replaceState, supportsPushState } from '../util/push-state' export class HashHistory extends History { - constructor (router: Router, base: ?string, fallback: boolean) { + constructor (router: Router, base: ?string) { super(router, base) // check history fallback deeplinking - if (fallback && checkFallback(this.base)) { + if (checkFallback(this.base)) { return } ensureSlash() @@ -80,10 +80,13 @@ export class HashHistory extends History { function checkFallback (base) { const location = getLocation(base) - if (!/^\/#/.test(location)) { - window.location.replace( - cleanPath(base + '/#' + location) - ) + if (location !== '/' && !/^\/#/.test(location)) { + const path = cleanPath(base + '/#' + location) + if (supportsPushState) { + replaceState(path) + } else { + window.location.replace(path) + } return true } } diff --git a/src/index.js b/src/index.js index a1a7b8507..8bbfc21c5 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ export default class VueRouter { this.history = new HTML5History(this, options.base) break case 'hash': - this.history = new HashHistory(this, options.base, this.fallback) + this.history = new HashHistory(this, options.base) break case 'abstract': this.history = new AbstractHistory(this, options.base) From c79a7243cd728a9d087535a37563c15e8e0382a8 Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Tue, 19 Jun 2018 10:44:58 +0200 Subject: [PATCH 2/6] Add hash mode deeplinking test --- test/e2e/specs/hash-mode.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/hash-mode.js b/test/e2e/specs/hash-mode.js index d32d4d0dd..d6c0f3061 100644 --- a/test/e2e/specs/hash-mode.js +++ b/test/e2e/specs/hash-mode.js @@ -2,7 +2,7 @@ module.exports = { 'Hash mode': function (browser) { browser .url('http://localhost:8080/hash-mode/') - .waitForElementVisible('#app', 1000) + .waitForElementVisible('#app', 2000) .assert.count('li', 5) .assert.count('li a', 4) .assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/') @@ -27,7 +27,7 @@ module.exports = { .assert.urlEquals('http://localhost:8080/hash-mode/#/bar') .assert.containsText('.view', 'bar') - // check initial visit + // check initial visit .url('http://localhost:8080/hash-mode/#/foo') .waitForElementVisible('#app', 1000) .assert.containsText('.view', 'foo') @@ -35,5 +35,17 @@ module.exports = { .waitForElementVisible('#app', 1000) .assert.containsText('.view', 'unicode') .end() + + // check hash placed correctly + .url('http://localhost:8080/hash-mode/foo?page=123') + .waitForElementVisible('#app', 1000) + .assert.urlEquals('http://localhost:8080/hash-mode/#/foo?page=123') + .assert.count('li', 4) + .assert.count('li a', 3) + .assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/') + .assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo') + .assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar') + .assert.containsText('.view', 'foo') + .end() } } From 2abe2d55605a54922813b6ceaa78e3c12b06811b Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Tue, 19 Jun 2018 10:45:35 +0200 Subject: [PATCH 3/6] Fix hash scroll bahavior test router base --- examples/hash-scroll-behavior/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/hash-scroll-behavior/app.js b/examples/hash-scroll-behavior/app.js index 0f1667e79..5cda05068 100644 --- a/examples/hash-scroll-behavior/app.js +++ b/examples/hash-scroll-behavior/app.js @@ -52,6 +52,7 @@ const scrollBehavior = (to, from, savedPosition) => { const router = new VueRouter({ mode: 'hash', + base: __dirname, scrollBehavior, routes: [ { path: '/', component: Home, meta: { scrollToTop: true }}, From fc99abf76e47a756ca00af3e07a8618525dd0e89 Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Tue, 19 Jun 2018 10:45:51 +0200 Subject: [PATCH 4/6] Add hash scroll behavior to examples list --- examples/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/index.html b/examples/index.html index f2bdf7225..13dcb3793 100644 --- a/examples/index.html +++ b/examples/index.html @@ -21,6 +21,7 @@

Vue Router Examples

  • Data Fetching
  • Navigation Guards
  • Scroll Behavior
  • +
  • Hash Scroll Behavior
  • Lazy Loading
  • Auth Flow
  • Discrete Components
  • From bb2aed99e1ba66701bb7572c65f02f15b1f8334b Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Tue, 19 Jun 2018 11:02:00 +0200 Subject: [PATCH 5/6] Undo unnecessary timeout increase --- test/e2e/specs/hash-mode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/hash-mode.js b/test/e2e/specs/hash-mode.js index d6c0f3061..028e69bb1 100644 --- a/test/e2e/specs/hash-mode.js +++ b/test/e2e/specs/hash-mode.js @@ -2,7 +2,7 @@ module.exports = { 'Hash mode': function (browser) { browser .url('http://localhost:8080/hash-mode/') - .waitForElementVisible('#app', 2000) + .waitForElementVisible('#app', 1000) .assert.count('li', 5) .assert.count('li a', 4) .assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/') From 4be938e67d190569e403eefa9c57b90a000d9fed Mon Sep 17 00:00:00 2001 From: Emanuel Mutschlechner Date: Mon, 10 Sep 2018 02:12:43 +0200 Subject: [PATCH 6/6] Update hash-mode.js --- test/e2e/specs/hash-mode.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/e2e/specs/hash-mode.js b/test/e2e/specs/hash-mode.js index 028e69bb1..1c0f8f865 100644 --- a/test/e2e/specs/hash-mode.js +++ b/test/e2e/specs/hash-mode.js @@ -34,17 +34,11 @@ module.exports = { .url('http://localhost:8080/hash-mode/#/%C3%A9') .waitForElementVisible('#app', 1000) .assert.containsText('.view', 'unicode') - .end() // check hash placed correctly .url('http://localhost:8080/hash-mode/foo?page=123') .waitForElementVisible('#app', 1000) .assert.urlEquals('http://localhost:8080/hash-mode/#/foo?page=123') - .assert.count('li', 4) - .assert.count('li a', 3) - .assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/') - .assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo') - .assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar') .assert.containsText('.view', 'foo') .end() }