ThePainnn
ThePainnn

Reputation: 441

Getting initial state from redux when navigating directly to url

When user navigation to app ex: http://myapp.mydomain.com I initialize a bunch of stuff, make requests to auth the user based on a cookie etc. This setup the main state of my main-reducer.

If a user navigation directly by pasting let say: http://myapp.mydomain.com/userProfile

The main state, will never be setupped. So the trick I'm using is putting the last part of the url (userProfile) in a cookie (or somewhere else) and redirecting to http://myapp.mydomain.com. After auth and requests, I the redirect back to the page the user wants to view. This works, but feels wrong. I was wondering: is there a better way of doing that?

Thanks!

Upvotes: 0

Views: 157

Answers (1)

Neeraj
Neeraj

Reputation: 483

Why don't you just make the route /userProfile as protected route.

Only if the user is authenticated he can see that page if not redirect to root page and re-validate the user.

Upvotes: 1

Related Questions