From 427ade711cf98d19e9e848c2c98177d1a3c98ffa Mon Sep 17 00:00:00 2001 From: Jairo Caro-Accino Viciana Date: Wed, 25 Apr 2018 18:29:44 +0200 Subject: [PATCH 1/2] BasePath --- src/Route.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Route.js b/src/Route.js index c4a4ea5..4b1b6fe 100644 --- a/src/Route.js +++ b/src/Route.js @@ -2,7 +2,19 @@ import { parseRoute } from "./parseRoute" export function Route(props) { return function(state, actions) { - var location = state.location + var location = state.location; + // Basepath must end with / + if(props.basepath && props.basepath[props.basepath.length] !== "/"){ + props.basepath += "/"; + } + // Remove basepath from path + if(~props.path.indexOf(props.basepath)){ + props.path = props.path.split(props.basepath)[1]; + } + // Remove basepath from url + if(~location.pathname.indexOf(props.basepath)){ + location.pathname = location.pathname.split(props.basepath)[1]; + } var match = parseRoute(props.path, location.pathname, { exact: !props.parent }) From 65b39fd2b91a1edab69535e2565d543fed379d7b Mon Sep 17 00:00:00 2001 From: Jairo Caro-Accino Viciana Date: Wed, 25 Apr 2018 18:40:39 +0200 Subject: [PATCH 2/2] fix fix unchecked variables --- src/Route.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Route.js b/src/Route.js index 4b1b6fe..db1f475 100644 --- a/src/Route.js +++ b/src/Route.js @@ -8,11 +8,11 @@ export function Route(props) { props.basepath += "/"; } // Remove basepath from path - if(~props.path.indexOf(props.basepath)){ + if(props.path && ~props.path.indexOf(props.basepath)){ props.path = props.path.split(props.basepath)[1]; } // Remove basepath from url - if(~location.pathname.indexOf(props.basepath)){ + if(location.pathname && ~location.pathname.indexOf(props.basepath)){ location.pathname = location.pathname.split(props.basepath)[1]; } var match = parseRoute(props.path, location.pathname, {