Skip to content

Commit f507dcb

Browse files
author
woodcutter
committed
feat(routeToLocation): disable '//' situation in urls
1 parent 391fd33 commit f507dcb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-unity-router",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "Redux router that syncs history with store",
55
"main": "dist/index.js",
66
"scripts": {
@@ -42,7 +42,7 @@
4242
"dependencies": {
4343
"history": "^4.6.3",
4444
"path": "^0.12.7",
45-
"path-to-regexp": "^1.6.0",
45+
"path-to-regexp": "^2.4.0",
4646
"prop-types": "^15.5.10",
4747
"query-string": "^4.3.4",
4848
"url": "^0.11.0"

src/parsers/routeToLocation.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ const createMatchRouteToPath = registry => ({ id, params = {}, query = {}, hash
1919
let pathname;
2020

2121
try {
22-
// path-to-regexp (1.6.0): encodeURI by default, disable it with decodeURI
22+
// remove front trailing backslash (disable '//' situation)
23+
Object.keys(params).forEach(name => {
24+
params[name] = (params[name] || '').replace(/^\//, '');
25+
});
26+
27+
// path-to-regexp (2.4.0): encodeURI by default, disable it with encode option
2328
// 'pretty' flag disable all encoding, besides '/', '?', '#'
24-
pathname = decodeURIComponent(matcher(params));
29+
pathname = matcher(params, { encode: value => value });
2530
} catch (e) {
2631
throw new RouterError(e.toString());
2732
}

0 commit comments

Comments
 (0)