reactjs - Redirect after login to the original url in react-router -


hi using erikras' react-redux-universal-hot-example

my problem trying visit page lets "/chat" , in doing should redirected "/login" page since needs authentication. once complete authentication should redirected original url "/chat".

i trying use onenter hook didn't work. after login redirecting users "/loginsuccess" page default (hard coded)

thanks in advance help

here's how approach high level...

  1. when redirect /login, add current route next route's location state.
  2. handle login.
  3. when navigating /loginsuccess, check location state route passed, , redirect that.

it this...

// function passed onenter handle authentication check redirectifnotloggedin(nextstate, replace) {   if (notloggedin) {     replace({       pathname: '/login',       state: {         redirectto: nextstate.location.pathname       }     })   } }  // function passed onenter handle loginsucesss redirect redirectafterloggedin(nextstate, replace) {   if(nextstate.location.state.redirectto) {     replace(nextstate.location.state.redirectto) // might need prepend '/'   } } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -