From 128a7d62693af47db297841fc5a2c9c367a6322b Mon Sep 17 00:00:00 2001 From: Kevin Smithson Date: Tue, 28 Feb 2017 13:48:05 -0800 Subject: [PATCH 01/12] added caseSensitive and pathToRegexpOptions to RouteConfig and pathToRegexpOptions to RouteRecord. Used to support senstive matches and pass along more options to pathToRegexp. #1214 --- examples/redirect/app.js | 14 ++++++++++++++ flow/declarations.js | 9 +++++++++ src/create-route-map.js | 11 ++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/examples/redirect/app.js b/examples/redirect/app.js index d81664c85..732fee3d8 100644 --- a/examples/redirect/app.js +++ b/examples/redirect/app.js @@ -50,6 +50,12 @@ const router = new VueRouter({ // redirect with params { path: '/redirect-with-params/:id', redirect: '/with-params/:id' }, + // redirect with caseSensitive + { path: '/foobar', redirect: '/FooBar', caseSensitive: true }, + + // redirect with pathToRegexpOptions + { path: '/FooBar', redirect: '/bar', pathToRegexpOptions: { sensitive: true }}, + // catch all redirect { path: '*', redirect: '/' } ] @@ -96,6 +102,14 @@ new Vue({
  • /redirect-with-params/123 (redirects to /with-params/123)
  • + +
  • + /foobar (redirects to /FooBar) +
  • + +
  • + /FooBar (redirects to /bar) +
  • /not-found (redirects to /) diff --git a/flow/declarations.js b/flow/declarations.js index 91ed03ef8..e83fe6b49 100644 --- a/flow/declarations.js +++ b/flow/declarations.js @@ -37,6 +37,12 @@ declare type RouterOptions = { declare type RedirectOption = RawLocation | ((to: Route) => RawLocation) +declare type PathToRegexpOptions = { + sensitive?: boolean, + strict?: boolean, + end?: boolean +} + declare type RouteConfig = { path: string; name?: string; @@ -48,6 +54,8 @@ declare type RouteConfig = { beforeEnter?: NavigationGuard; meta?: any; props?: boolean | Object | Function; + caseSensitive?: boolean; + pathToRegexpOptions?: PathToRegexpOptions; } declare type RouteRecord = { @@ -62,6 +70,7 @@ declare type RouteRecord = { beforeEnter: ?NavigationGuard; meta: any; props: boolean | Object | Function | Dictionary; + pathToRegexpOptions: PathToRegexpOptions; } declare type Location = { diff --git a/src/create-route-map.js b/src/create-route-map.js index c68d211b7..f35fc06cd 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -58,8 +58,15 @@ function addRouteRecord ( } const normalizedPath = normalizePath(path, parent) + const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {} + + if (typeof route.caseSensitive === 'boolean') { + pathToRegexpOptions.sensitive = route.caseSensitive + } + const record: RouteRecord = { path: normalizedPath, + // TODO pass pathToRegexpOptions regex: compileRouteRegex(normalizedPath), components: route.components || { default: route.component }, instances: {}, @@ -73,7 +80,8 @@ function addRouteRecord ( ? {} : route.components ? route.props - : { default: route.props } + : { default: route.props }, + pathToRegexpOptions: pathToRegexpOptions } if (route.children) { @@ -136,6 +144,7 @@ function addRouteRecord ( } } +// TODO add regex options function compileRouteRegex (path: string): RouteRegExp { const regex = Regexp(path) if (process.env.NODE_ENV !== 'production') { From f6b213db44c966e55c0f9eff84e4e9bc23d66c69 Mon Sep 17 00:00:00 2001 From: Kevin Smithson Date: Tue, 28 Feb 2017 13:50:05 -0800 Subject: [PATCH 02/12] changed test for /FooBar to redirect to /FOOBAR --- examples/redirect/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/redirect/app.js b/examples/redirect/app.js index 732fee3d8..c40c1dadf 100644 --- a/examples/redirect/app.js +++ b/examples/redirect/app.js @@ -54,7 +54,7 @@ const router = new VueRouter({ { path: '/foobar', redirect: '/FooBar', caseSensitive: true }, // redirect with pathToRegexpOptions - { path: '/FooBar', redirect: '/bar', pathToRegexpOptions: { sensitive: true }}, + { path: '/FooBar', redirect: '/FOOBAR', pathToRegexpOptions: { sensitive: true }}, // catch all redirect { path: '*', redirect: '/' } From 61624534bbcb2d331d03ce4aaf90791c3df91bad Mon Sep 17 00:00:00 2001 From: Kevin Smithson Date: Wed, 1 Mar 2017 07:53:43 -0800 Subject: [PATCH 03/12] fixed tests and added 2 tests for case sensitive redirects --- examples/redirect/app.js | 2 +- test/e2e/specs/redirect.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/redirect/app.js b/examples/redirect/app.js index c40c1dadf..7fee6c7e8 100644 --- a/examples/redirect/app.js +++ b/examples/redirect/app.js @@ -108,7 +108,7 @@ new Vue({
  • - /FooBar (redirects to /bar) + /FooBar (redirects to /FOOBAR)
  • diff --git a/test/e2e/specs/redirect.js b/test/e2e/specs/redirect.js index f91e66342..2124f0142 100644 --- a/test/e2e/specs/redirect.js +++ b/test/e2e/specs/redirect.js @@ -3,7 +3,7 @@ module.exports = { browser .url('http://localhost:8080/redirect/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 10) + .assert.count('li a', 12) // assert correct href with base .assert.attributeContains('li:nth-child(1) a', 'href', '/redirect/relative-redirect') .assert.attributeContains('li:nth-child(2) a', 'href', '/redirect/relative-redirect?foo=bar') @@ -14,7 +14,9 @@ module.exports = { .assert.attributeContains('li:nth-child(7) a', 'href', '/redirect/dynamic-redirect#baz') .assert.attributeContains('li:nth-child(8) a', 'href', '/redirect/named-redirect') .assert.attributeContains('li:nth-child(9) a', 'href', '/redirect/redirect-with-params/123') - .assert.attributeContains('li:nth-child(10) a', 'href', '/not-found') + .assert.attributeContains('li:nth-child(10) a', 'href', '/redirect/foobar') + .assert.attributeContains('li:nth-child(11) a', 'href', '/redirect/FooBar') + .assert.attributeContains('li:nth-child(12) a', 'href', '/not-found') .assert.containsText('.view', 'default') @@ -58,6 +60,14 @@ module.exports = { .assert.urlEquals('http://localhost:8080/redirect/') .assert.containsText('.view', 'default') + .click('li:nth-child(11) a') + .assert.urlEquals('http://localhost:8080/redirect/') + .assert.containsText('.view', 'default') + + .click('li:nth-child(12) a') + .assert.urlEquals('http://localhost:8080/redirect/') + .assert.containsText('.view', 'default') + // check initial visit .url('http://localhost:8080/redirect/relative-redirect') .waitForElementVisible('#app', 1000) From eb5e80f34a12bae7fd1eb9af87635f2625ed0eb2 Mon Sep 17 00:00:00 2001 From: Kevin Smithson Date: Wed, 1 Mar 2017 08:07:51 -0800 Subject: [PATCH 04/12] added some route-matching tests --- examples/route-matching/app.js | 13 ++++++++- test/e2e/specs/route-matching.js | 49 +++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/examples/route-matching/app.js b/examples/route-matching/app.js index 2d0b6b6f1..bc1295bb9 100644 --- a/examples/route-matching/app.js +++ b/examples/route-matching/app.js @@ -21,7 +21,14 @@ const router = new VueRouter({ // asterisk can match anything { path: '/asterisk/*' }, // make part of the path optional by wrapping with parens and add "?" - { path: '/optional-group/(foo/)?bar' } + { path: '/optional-group/(foo/)?bar' }, + + // caseSensitive match + { path: '/FooBar', caseSensitive: true }, + { path: '/FOOBar', pathToRegexpOptions: { sensitive: true }}, + // Not case sensitive (which is default) + { path: '/foo', caseSensitive: false }, + { path: '/FOO', caseSensitive: false } // Should match /foo ] }) @@ -41,6 +48,10 @@ new Vue({
  • /asterisk/foo/bar
  • /optional-group/bar
  • /optional-group/foo/bar
  • +
  • /FooBar
  • +
  • /FOOBar
  • +
  • /foo
  • +
  • /FOO
  • Route context

    {{ JSON.stringify($route, null, 2) }}
    diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index 79e5b3745..b3bc202ae 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -3,7 +3,7 @@ module.exports = { browser .url('http://localhost:8080/route-matching/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 10) + .assert.count('li a', 14) .assert.evaluate(function () { var route = JSON.parse(document.querySelector('pre').textContent) return ( @@ -125,6 +125,53 @@ module.exports = { ) }, null, '/optional-group/foo/bar') + .click('li:nth-child(11) a') + .assert.evaluate(function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/FooBar' && + route.fullPath === '/FooBar' && + JSON.stringify(route.params) === JSON.stringify({}) && + route.matched[0].pathToRegexpOptions.sensitive === true + ) + }, null, '/FooBar') + + .click('li:nth-child(12) a') + .assert.evaluate(function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/FOOBar' && + route.fullPath === '/FOOBar' && + JSON.stringify(route.params) === JSON.stringify({}) && + route.matched[0].pathToRegexpOptions.sensitive === true + ) + }, null, '/FOOBar') + + .click('li:nth-child(13) a') + .assert.evaluate(function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/foo' && + route.fullPath === '/foo' && + JSON.stringify(route.params) === JSON.stringify({}) && + route.matched[0].pathToRegexpOptions.sensitive === false + ) + }, null, '/foo') + + .click('li:nth-child(14) a') + .assert.evaluate(function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/foo' && + route.fullPath === '/FOO' && + JSON.stringify(route.params) === JSON.stringify({}) && + route.matched[0].pathToRegexpOptions.sensitive === false + ) + }, null, '/FOOBar') .end() } } From ca81b9df71a8c5352597422f0f521b7ffdb730b5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 14 Mar 2017 17:23:06 +0100 Subject: [PATCH 05/12] Update create-route-map.js --- src/create-route-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create-route-map.js b/src/create-route-map.js index f35fc06cd..92f3d9331 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -81,7 +81,7 @@ function addRouteRecord ( : route.components ? route.props : { default: route.props }, - pathToRegexpOptions: pathToRegexpOptions + pathToRegexpOptions } if (route.children) { From a3d4e5dfff600b9e0fd835f91c1b003393fb74bb Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 14 Mar 2017 17:27:03 +0100 Subject: [PATCH 06/12] Update route-matching.js --- test/e2e/specs/route-matching.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index b3bc202ae..d71725c45 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -171,7 +171,7 @@ module.exports = { JSON.stringify(route.params) === JSON.stringify({}) && route.matched[0].pathToRegexpOptions.sensitive === false ) - }, null, '/FOOBar') + }, null, '/FOO') .end() } } From ddfb1b8fa425987e5f1ad6865692a8d1d10f18fe Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 14:11:13 +0200 Subject: [PATCH 07/12] Update code to use caseSensitive option --- examples/redirect/app.js | 14 ++++++++------ flow/declarations.js | 2 +- src/create-route-map.js | 7 +++---- test/e2e/specs/redirect.js | 18 ++++++++++++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/examples/redirect/app.js b/examples/redirect/app.js index 7fee6c7e8..32beeb885 100644 --- a/examples/redirect/app.js +++ b/examples/redirect/app.js @@ -9,6 +9,8 @@ const Foo = { template: '
    foo
    ' } const Bar = { template: '
    bar
    ' } const Baz = { template: '
    baz
    ' } const WithParams = { template: '
    {{ $route.params.id }}
    ' } +const Foobar = { template: '
    foobar
    ' } +const FooBar = { template: '
    FooBar
    ' } const router = new VueRouter({ mode: 'history', @@ -51,10 +53,10 @@ const router = new VueRouter({ { path: '/redirect-with-params/:id', redirect: '/with-params/:id' }, // redirect with caseSensitive - { path: '/foobar', redirect: '/FooBar', caseSensitive: true }, + { path: '/foobar', component: Foobar, caseSensitive: true }, // redirect with pathToRegexpOptions - { path: '/FooBar', redirect: '/FOOBAR', pathToRegexpOptions: { sensitive: true }}, + { path: '/FooBar', component: FooBar, pathToRegexpOptions: { sensitive: true }}, // catch all redirect { path: '*', redirect: '/' } @@ -102,13 +104,13 @@ new Vue({
  • /redirect-with-params/123 (redirects to /with-params/123)
  • - +
  • - /foobar (redirects to /FooBar) + /foobar
  • - +
  • - /FooBar (redirects to /FOOBAR) + /FooBar
  • diff --git a/flow/declarations.js b/flow/declarations.js index e83fe6b49..a0128c780 100644 --- a/flow/declarations.js +++ b/flow/declarations.js @@ -6,7 +6,7 @@ declare class RouteRegExp extends RegExp { declare module 'path-to-regexp' { declare var exports: { - (path: string, keys?: Array): RouteRegExp; + (path: string, keys?: Array, options?: Object): RouteRegExp; compile: (path: string) => (params: Object) => string; } } diff --git a/src/create-route-map.js b/src/create-route-map.js index 92f3d9331..53566feae 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -66,8 +66,7 @@ function addRouteRecord ( const record: RouteRecord = { path: normalizedPath, - // TODO pass pathToRegexpOptions - regex: compileRouteRegex(normalizedPath), + regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), components: route.components || { default: route.component }, instances: {}, name, @@ -145,8 +144,8 @@ function addRouteRecord ( } // TODO add regex options -function compileRouteRegex (path: string): RouteRegExp { - const regex = Regexp(path) +function compileRouteRegex (path: string, pathToRegexpOptions: PathToRegexpOptions): RouteRegExp { + const regex = Regexp(path, [], pathToRegexpOptions) if (process.env.NODE_ENV !== 'production') { const keys: any = {} regex.keys.forEach(key => { diff --git a/test/e2e/specs/redirect.js b/test/e2e/specs/redirect.js index 2124f0142..ba39d3b7a 100644 --- a/test/e2e/specs/redirect.js +++ b/test/e2e/specs/redirect.js @@ -57,12 +57,12 @@ module.exports = { .assert.containsText('.view', '123') .click('li:nth-child(10) a') - .assert.urlEquals('http://localhost:8080/redirect/') - .assert.containsText('.view', 'default') + .assert.urlEquals('http://localhost:8080/redirect/foobar') + .assert.containsText('.view', 'foobar') .click('li:nth-child(11) a') - .assert.urlEquals('http://localhost:8080/redirect/') - .assert.containsText('.view', 'default') + .assert.urlEquals('http://localhost:8080/redirect/FooBar') + .assert.containsText('.view', 'FooBar') .click('li:nth-child(12) a') .assert.urlEquals('http://localhost:8080/redirect/') @@ -114,6 +114,16 @@ module.exports = { .assert.urlEquals('http://localhost:8080/redirect/with-params/123') .assert.containsText('.view', '123') + .url('http://localhost:8080/redirect/foobar') + .waitForElementVisible('#app', 1000) + .assert.urlEquals('http://localhost:8080/redirect/foobar') + .assert.containsText('.view', 'foobar') + + .url('http://localhost:8080/redirect/FooBar') + .waitForElementVisible('#app', 1000) + .assert.urlEquals('http://localhost:8080/redirect/FooBar') + .assert.containsText('.view', 'FooBar') + .url('http://localhost:8080/redirect/not-found') .waitForElementVisible('#app', 1000) .assert.urlEquals('http://localhost:8080/redirect/') From fb08ffae9b88bace213bf11e05ffec54121aa48c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 14:54:17 +0200 Subject: [PATCH 08/12] Add unit test for caseSensitive --- src/create-route-map.js | 4 +--- test/unit/specs/create-map.spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/create-route-map.js b/src/create-route-map.js index 53566feae..bd865a27c 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -79,8 +79,7 @@ function addRouteRecord ( ? {} : route.components ? route.props - : { default: route.props }, - pathToRegexpOptions + : { default: route.props } } if (route.children) { @@ -143,7 +142,6 @@ function addRouteRecord ( } } -// TODO add regex options function compileRouteRegex (path: string, pathToRegexpOptions: PathToRegexpOptions): RouteRegExp { const regex = Regexp(path, [], pathToRegexpOptions) if (process.env.NODE_ENV !== 'production') { diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index ff1ccf46d..fff3ea4d6 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -3,6 +3,8 @@ import { createRouteMap } from '../../../src/create-route-map' const Home = { template: '
    This is Home
    ' } const Foo = { template: '
    This is Foo
    ' } +const FooBar = { template: '
    This is FooBar
    ' } +const Foobar = { template: '
    This is foobar
    ' } const Bar = { template: '
    This is Bar
    ' } const Baz = { template: '
    This is Baz
    ' } @@ -74,4 +76,21 @@ describe('Creating Route Map', function () { expect(console.warn).toHaveBeenCalled() expect(console.warn.calls.argsFor(0)[0]).toMatch('vue-router] Duplicate param keys in route with path: "/foo/:id/bar/:id"') }) + + describe('path-to-regexp options', function () { + const routes = [ + { path: '/foo', name: 'foo', component: Foo }, + { path: '/bar', name: 'bar', component: Bar, caseSensitive: false }, + { path: '/FooBar', name: 'FooBar', component: FooBar, caseSensitive: true }, + { path: '/foobar', name: 'foobar', component: Foobar, caseSensitive: true } + ] + + it('caseSensitive option in routes', function () { + const { nameMap } = createRouteMap(routes) + + expect(nameMap.FooBar.regex.ignoreCase).toBe(false) + expect(nameMap.bar.regex.ignoreCase).toBe(true) + expect(nameMap.foo.regex.ignoreCase).toBe(true) + }) + }) }) From 07ce35c07b8199047be1ae1571353e1d03990de5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 15:08:49 +0200 Subject: [PATCH 09/12] Add test for pathToRegexpOptions in route --- test/unit/specs/create-map.spec.js | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index fff3ea4d6..ad5803d1c 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -85,12 +85,52 @@ describe('Creating Route Map', function () { { path: '/foobar', name: 'foobar', component: Foobar, caseSensitive: true } ] - it('caseSensitive option in routes', function () { + it('caseSensitive option in route', function () { const { nameMap } = createRouteMap(routes) expect(nameMap.FooBar.regex.ignoreCase).toBe(false) expect(nameMap.bar.regex.ignoreCase).toBe(true) expect(nameMap.foo.regex.ignoreCase).toBe(true) }) + + it('pathToRegexpOptions option in route', function () { + const { nameMap } = createRouteMap([ + { + name: 'foo', + path: '/foo', + component: Foo, + pathToRegexpOptions: { + sensitive: true + } + }, + { + name: 'bar', + path: '/bar', + component: Bar, + pathToRegexpOptions: { + sensitive: false + } + } + ]) + + expect(nameMap.foo.regex.ignoreCase).toBe(false) + expect(nameMap.bar.regex.ignoreCase).toBe(true) + }) + + it('caseSensitive over pathToRegexpOptions in route', function () { + const { nameMap } = createRouteMap([ + { + name: 'foo', + path: '/foo', + component: Foo, + caseSensitive: true, + pathToRegexpOptions: { + sensitive: false + } + } + ]) + + expect(nameMap.foo.regex.ignoreCase).toBe(false) + }) }) }) From e1e551c22ecd383cab59a219d5309fc90f199f03 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 15:13:38 +0200 Subject: [PATCH 10/12] Fix flow typings --- flow/declarations.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/flow/declarations.js b/flow/declarations.js index a0128c780..e62aeb9f9 100644 --- a/flow/declarations.js +++ b/flow/declarations.js @@ -4,9 +4,15 @@ declare class RouteRegExp extends RegExp { keys: Array<{ name: string, optional: boolean }>; } +declare type PathToRegexpOptions = { + sensitive?: boolean, + strict?: boolean, + end?: boolean +} + declare module 'path-to-regexp' { declare var exports: { - (path: string, keys?: Array, options?: Object): RouteRegExp; + (path: string, keys?: Array, options?: PathToRegexpOptions): RouteRegExp; compile: (path: string) => (params: Object) => string; } } @@ -37,12 +43,6 @@ declare type RouterOptions = { declare type RedirectOption = RawLocation | ((to: Route) => RawLocation) -declare type PathToRegexpOptions = { - sensitive?: boolean, - strict?: boolean, - end?: boolean -} - declare type RouteConfig = { path: string; name?: string; @@ -70,7 +70,6 @@ declare type RouteRecord = { beforeEnter: ?NavigationGuard; meta: any; props: boolean | Object | Function | Dictionary; - pathToRegexpOptions: PathToRegexpOptions; } declare type Location = { From 6fd4a5d31710dbdd581e6c9f08412171ab04bb65 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 15:16:19 +0200 Subject: [PATCH 11/12] Add ts types --- types/router.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/router.d.ts b/types/router.d.ts index ac702ab11..6992461de 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -60,6 +60,12 @@ export interface RouterOptions { type RoutePropsFunction = (route: Route) => Object; +export interface PathToRegexpOptions { + sensitive?: boolean; + strict?: boolean; + end?: boolean; +} + export interface RouteConfig { path: string; name?: string; @@ -71,6 +77,8 @@ export interface RouteConfig { meta?: any; beforeEnter?: NavigationGuard; props?: boolean | Object | RoutePropsFunction; + caseSensitive?: boolean; + pathToRegexpOptions?: PathToRegexpOptions; } export interface RouteRecord { From c992a52203424b2be036ca746e2957d5a0881c4d Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 May 2017 15:40:04 +0200 Subject: [PATCH 12/12] Remove old test --- examples/route-matching/app.js | 13 +-------- test/e2e/specs/route-matching.js | 50 +------------------------------- 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/examples/route-matching/app.js b/examples/route-matching/app.js index bc1295bb9..2d0b6b6f1 100644 --- a/examples/route-matching/app.js +++ b/examples/route-matching/app.js @@ -21,14 +21,7 @@ const router = new VueRouter({ // asterisk can match anything { path: '/asterisk/*' }, // make part of the path optional by wrapping with parens and add "?" - { path: '/optional-group/(foo/)?bar' }, - - // caseSensitive match - { path: '/FooBar', caseSensitive: true }, - { path: '/FOOBar', pathToRegexpOptions: { sensitive: true }}, - // Not case sensitive (which is default) - { path: '/foo', caseSensitive: false }, - { path: '/FOO', caseSensitive: false } // Should match /foo + { path: '/optional-group/(foo/)?bar' } ] }) @@ -48,10 +41,6 @@ new Vue({
  • /asterisk/foo/bar
  • /optional-group/bar
  • /optional-group/foo/bar
  • -
  • /FooBar
  • -
  • /FOOBar
  • -
  • /foo
  • -
  • /FOO
  • Route context

    {{ JSON.stringify($route, null, 2) }}
    diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index d71725c45..ea1ef3a29 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -3,7 +3,7 @@ module.exports = { browser .url('http://localhost:8080/route-matching/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 14) + .assert.count('li a', 10) .assert.evaluate(function () { var route = JSON.parse(document.querySelector('pre').textContent) return ( @@ -124,54 +124,6 @@ module.exports = { }) ) }, null, '/optional-group/foo/bar') - - .click('li:nth-child(11) a') - .assert.evaluate(function () { - var route = JSON.parse(document.querySelector('pre').textContent) - return ( - route.matched.length === 1 && - route.matched[0].path === '/FooBar' && - route.fullPath === '/FooBar' && - JSON.stringify(route.params) === JSON.stringify({}) && - route.matched[0].pathToRegexpOptions.sensitive === true - ) - }, null, '/FooBar') - - .click('li:nth-child(12) a') - .assert.evaluate(function () { - var route = JSON.parse(document.querySelector('pre').textContent) - return ( - route.matched.length === 1 && - route.matched[0].path === '/FOOBar' && - route.fullPath === '/FOOBar' && - JSON.stringify(route.params) === JSON.stringify({}) && - route.matched[0].pathToRegexpOptions.sensitive === true - ) - }, null, '/FOOBar') - - .click('li:nth-child(13) a') - .assert.evaluate(function () { - var route = JSON.parse(document.querySelector('pre').textContent) - return ( - route.matched.length === 1 && - route.matched[0].path === '/foo' && - route.fullPath === '/foo' && - JSON.stringify(route.params) === JSON.stringify({}) && - route.matched[0].pathToRegexpOptions.sensitive === false - ) - }, null, '/foo') - - .click('li:nth-child(14) a') - .assert.evaluate(function () { - var route = JSON.parse(document.querySelector('pre').textContent) - return ( - route.matched.length === 1 && - route.matched[0].path === '/foo' && - route.fullPath === '/FOO' && - JSON.stringify(route.params) === JSON.stringify({}) && - route.matched[0].pathToRegexpOptions.sensitive === false - ) - }, null, '/FOO') .end() } }