Skip to content

Commit ddfb1b8

Browse files
committed
Update code to use caseSensitive option
1 parent a3d4e5d commit ddfb1b8

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

examples/redirect/app.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const Foo = { template: '<div>foo</div>' }
99
const Bar = { template: '<div>bar</div>' }
1010
const Baz = { template: '<div>baz</div>' }
1111
const WithParams = { template: '<div>{{ $route.params.id }}</div>' }
12+
const Foobar = { template: '<div>foobar</div>' }
13+
const FooBar = { template: '<div>FooBar</div>' }
1214

1315
const router = new VueRouter({
1416
mode: 'history',
@@ -51,10 +53,10 @@ const router = new VueRouter({
5153
{ path: '/redirect-with-params/:id', redirect: '/with-params/:id' },
5254

5355
// redirect with caseSensitive
54-
{ path: '/foobar', redirect: '/FooBar', caseSensitive: true },
56+
{ path: '/foobar', component: Foobar, caseSensitive: true },
5557

5658
// redirect with pathToRegexpOptions
57-
{ path: '/FooBar', redirect: '/FOOBAR', pathToRegexpOptions: { sensitive: true }},
59+
{ path: '/FooBar', component: FooBar, pathToRegexpOptions: { sensitive: true }},
5860

5961
// catch all redirect
6062
{ path: '*', redirect: '/' }
@@ -102,13 +104,13 @@ new Vue({
102104
<li><router-link to="/redirect-with-params/123">
103105
/redirect-with-params/123 (redirects to /with-params/123)
104106
</router-link></li>
105-
107+
106108
<li><router-link to="/foobar">
107-
/foobar (redirects to /FooBar)
109+
/foobar
108110
</router-link></li>
109-
111+
110112
<li><router-link to="/FooBar">
111-
/FooBar (redirects to /FOOBAR)
113+
/FooBar
112114
</router-link></li>
113115
114116
<li><router-link to="/not-found">

flow/declarations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare class RouteRegExp extends RegExp {
66

77
declare module 'path-to-regexp' {
88
declare var exports: {
9-
(path: string, keys?: Array<?{ name: string }>): RouteRegExp;
9+
(path: string, keys?: Array<?{ name: string }>, options?: Object): RouteRegExp;
1010
compile: (path: string) => (params: Object) => string;
1111
}
1212
}

src/create-route-map.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ function addRouteRecord (
6666

6767
const record: RouteRecord = {
6868
path: normalizedPath,
69-
// TODO pass pathToRegexpOptions
70-
regex: compileRouteRegex(normalizedPath),
69+
regex: compileRouteRegex(normalizedPath, pathToRegexpOptions),
7170
components: route.components || { default: route.component },
7271
instances: {},
7372
name,
@@ -145,8 +144,8 @@ function addRouteRecord (
145144
}
146145

147146
// TODO add regex options
148-
function compileRouteRegex (path: string): RouteRegExp {
149-
const regex = Regexp(path)
147+
function compileRouteRegex (path: string, pathToRegexpOptions: PathToRegexpOptions): RouteRegExp {
148+
const regex = Regexp(path, [], pathToRegexpOptions)
150149
if (process.env.NODE_ENV !== 'production') {
151150
const keys: any = {}
152151
regex.keys.forEach(key => {

test/e2e/specs/redirect.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ module.exports = {
5757
.assert.containsText('.view', '123')
5858

5959
.click('li:nth-child(10) a')
60-
.assert.urlEquals('http://localhost:8080/redirect/')
61-
.assert.containsText('.view', 'default')
60+
.assert.urlEquals('http://localhost:8080/redirect/foobar')
61+
.assert.containsText('.view', 'foobar')
6262

6363
.click('li:nth-child(11) a')
64-
.assert.urlEquals('http://localhost:8080/redirect/')
65-
.assert.containsText('.view', 'default')
64+
.assert.urlEquals('http://localhost:8080/redirect/FooBar')
65+
.assert.containsText('.view', 'FooBar')
6666

6767
.click('li:nth-child(12) a')
6868
.assert.urlEquals('http://localhost:8080/redirect/')
@@ -114,6 +114,16 @@ module.exports = {
114114
.assert.urlEquals('http://localhost:8080/redirect/with-params/123')
115115
.assert.containsText('.view', '123')
116116

117+
.url('http://localhost:8080/redirect/foobar')
118+
.waitForElementVisible('#app', 1000)
119+
.assert.urlEquals('http://localhost:8080/redirect/foobar')
120+
.assert.containsText('.view', 'foobar')
121+
122+
.url('http://localhost:8080/redirect/FooBar')
123+
.waitForElementVisible('#app', 1000)
124+
.assert.urlEquals('http://localhost:8080/redirect/FooBar')
125+
.assert.containsText('.view', 'FooBar')
126+
117127
.url('http://localhost:8080/redirect/not-found')
118128
.waitForElementVisible('#app', 1000)
119129
.assert.urlEquals('http://localhost:8080/redirect/')

0 commit comments

Comments
 (0)