diff --git a/package.json b/package.json index 2fc513c..f082ac2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-unity-router", - "version": "1.5.0", + "version": "1.6.0", "description": "Redux router that syncs history with store", "main": "dist/index.js", "scripts": { @@ -42,7 +42,7 @@ "dependencies": { "history": "^4.6.3", "path": "^0.12.7", - "path-to-regexp": "^1.6.0", + "path-to-regexp": "^2.4.0", "prop-types": "^15.5.10", "query-string": "^4.3.4", "url": "^0.11.0" diff --git a/src/parsers/routeToLocation.js b/src/parsers/routeToLocation.js index ec543b9..dd7dfb0 100644 --- a/src/parsers/routeToLocation.js +++ b/src/parsers/routeToLocation.js @@ -19,9 +19,14 @@ const createMatchRouteToPath = registry => ({ id, params = {}, query = {}, hash let pathname; try { - // path-to-regexp (1.6.0): encodeURI by default, disable it with decodeURI + // remove front trailing backslash (disable '//' situation) + Object.keys(params).forEach(name => { + params[name] = (params[name] || '').replace(/^\//, ''); + }); + + // path-to-regexp (2.4.0): encodeURI by default, disable it with encode option // 'pretty' flag disable all encoding, besides '/', '?', '#' - pathname = decodeURIComponent(matcher(params)); + pathname = matcher(params, { encode: value => value }); } catch (e) { throw new RouterError(e.toString()); }