Skip to content

Commit 128a7d6

Browse files
Kevin Smithsonposva
Kevin Smithson
authored andcommitted
added caseSensitive and pathToRegexpOptions to RouteConfig and pathToRegexpOptions to RouteRecord. Used to support senstive matches and pass along more options to pathToRegexp. vuejs#1214
1 parent 7283ae2 commit 128a7d6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

examples/redirect/app.js

+14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const router = new VueRouter({
5050
// redirect with params
5151
{ path: '/redirect-with-params/:id', redirect: '/with-params/:id' },
5252

53+
// redirect with caseSensitive
54+
{ path: '/foobar', redirect: '/FooBar', caseSensitive: true },
55+
56+
// redirect with pathToRegexpOptions
57+
{ path: '/FooBar', redirect: '/bar', pathToRegexpOptions: { sensitive: true }},
58+
5359
// catch all redirect
5460
{ path: '*', redirect: '/' }
5561
]
@@ -96,6 +102,14 @@ new Vue({
96102
<li><router-link to="/redirect-with-params/123">
97103
/redirect-with-params/123 (redirects to /with-params/123)
98104
</router-link></li>
105+
106+
<li><router-link to="/foobar">
107+
/foobar (redirects to /FooBar)
108+
</router-link></li>
109+
110+
<li><router-link to="/FooBar">
111+
/FooBar (redirects to /bar)
112+
</router-link></li>
99113
100114
<li><router-link to="/not-found">
101115
/not-found (redirects to /)

flow/declarations.js

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ declare type RouterOptions = {
3737

3838
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation)
3939

40+
declare type PathToRegexpOptions = {
41+
sensitive?: boolean,
42+
strict?: boolean,
43+
end?: boolean
44+
}
45+
4046
declare type RouteConfig = {
4147
path: string;
4248
name?: string;
@@ -48,6 +54,8 @@ declare type RouteConfig = {
4854
beforeEnter?: NavigationGuard;
4955
meta?: any;
5056
props?: boolean | Object | Function;
57+
caseSensitive?: boolean;
58+
pathToRegexpOptions?: PathToRegexpOptions;
5159
}
5260

5361
declare type RouteRecord = {
@@ -62,6 +70,7 @@ declare type RouteRecord = {
6270
beforeEnter: ?NavigationGuard;
6371
meta: any;
6472
props: boolean | Object | Function | Dictionary<boolean | Object | Function>;
73+
pathToRegexpOptions: PathToRegexpOptions;
6574
}
6675

6776
declare type Location = {

src/create-route-map.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ function addRouteRecord (
5858
}
5959

6060
const normalizedPath = normalizePath(path, parent)
61+
const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {}
62+
63+
if (typeof route.caseSensitive === 'boolean') {
64+
pathToRegexpOptions.sensitive = route.caseSensitive
65+
}
66+
6167
const record: RouteRecord = {
6268
path: normalizedPath,
69+
// TODO pass pathToRegexpOptions
6370
regex: compileRouteRegex(normalizedPath),
6471
components: route.components || { default: route.component },
6572
instances: {},
@@ -73,7 +80,8 @@ function addRouteRecord (
7380
? {}
7481
: route.components
7582
? route.props
76-
: { default: route.props }
83+
: { default: route.props },
84+
pathToRegexpOptions: pathToRegexpOptions
7785
}
7886

7987
if (route.children) {
@@ -136,6 +144,7 @@ function addRouteRecord (
136144
}
137145
}
138146

147+
// TODO add regex options
139148
function compileRouteRegex (path: string): RouteRegExp {
140149
const regex = Regexp(path)
141150
if (process.env.NODE_ENV !== 'production') {

0 commit comments

Comments
 (0)