Jekiwijaya / react-navigation-browser-history-helpers

React navigation for browser history
https://jekiwijaya.github.io/react-navigation-browser-history-helpers/
17 stars 6 forks source link

Issue when url finish with "/" #6

Open simonjoom opened 6 years ago

simonjoom commented 6 years ago

I constated that the helper cannot find the correct route in case or the browser add "/" at the end.

nota my screens path never finish by "/"

I added in reducer one line:

 const { path, params = {} } = Navigator.router.getPathAndParamsForState(state);
  //->  
  let pathf = path.lastIndexOf('/') !== -1 ? path.slice(0, path.lastIndexOf('/')) : path;
  //   
   const qs = queryToString(params);
      if (!action.dontPushHistory) {
        history.push({
          pathname: `${basePath}${pathf}`,
          search: qs,
        });
      }

same in browser history:

     setNavFromPath = (path) => {
       let pathWithoutQuery = path.indexOf('?') !== -1 ? path.slice(0, path.indexOf('?')) : path;
       pathWithoutQuery = path.lastIndexOf('/') !== -1 ? path.slice(0, path.lastIndexOf('/')) : path;
kopax commented 4 years ago

This sounds like the route are created with strict: true in term of react-router <Route /> terms. Did you sort this out?