Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Redux-simple-router and React-Router replaceState interactions #69

@ingro

Description

@ingro

Hello! I need to implement authentication mechanics to my application and so instead of starting from scratch I've used React-Router auth-flow example as example.

I'm facing a strange problem: from the Login component (roughly the same as the example above) I should be able to redirect to the previous visited route if auth is successfull:

if (loggedIn) {
   const { location, history } = this.props;

   if (location.state && location.state.nextPathname) {
       history.replaceState(null, location.state.nextPathname);
   } else {
       history.replaceState(null, '/');
   }
}

This path should be stored inside the location state object by the onEnter hook on a protected route:

function requireAuth(nextState, replaceState) {
    if (! isLoggedIn()) {
        replaceState({ nextPathname: nextState.location.pathname }, '/login');
    }
}

If I use this logic with redux-simple-route, inside the Login component the props this.location.state is null, while, if disabled, contains the right nextPathname property.

I think I've narrowed down the problem to these lines of redux-simple-router (68-71):

if(lastChangeId !== routing.changeId) {
  lastChangeId = routing.changeId;
  history.pushState(null, routing.path);
}

It pushes the route to history (which it should be not necessary) and doesn't pass the state in the process.

A simple fix would be setting changeId in the initial state to 0 but I don't know if it may cause other things to stop working...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions