1

I have a question about routing with React.

My goal

In a normal login, I use dispatch(push('/')) and the user jumps to the Home after log in, but I want the user to be redirected to the requested page (add info page in this repo) when log in from a link in the email sent to the user.(The URL have a token)

e.g. This link will be emailed. https://localhost/add-info/token

When the user presses the above link in the email, the user will be redirected to the login page and After logging in, I want the user to go to the information registration page instead of the home page.

I want to implement this, but I don't know how. Can someone please tell me how to do this?

via
  • 483
  • 1
  • 6
  • 17

2 Answers2

1

Simply add a query within the link provided to the user's mail, and then search for URL query every time a user enters the login page (in your login page backend code). this is how you read URL queries with JS...

Then provide a conditional dispatch in the end of the login algorithm for redirecting. like this:

if (url.query.redirectURL)
    dispatch(push('/' + url.query.redirectURL))

This is actually the concept...

Eldshe
  • 723
  • 6
  • 19
  • Thank you very much! You mean the url shoud have query like this? ```https://localhost/add-info ``` and no need to have user token? – via Apr 07 '21 at 12:00
  • 1
    Shape the data given in the url as you desire. Usually query comes like this: `https://your.domain.com/page?query1=data_you_chose&query2=data_you_chose` and your code then can read `query1` or `query2` when the browser gets to those pages. – Eldshe Apr 07 '21 at 13:28
0

enter image description t here

Provide a conditional dispatch in the end of the login algorithm for redirecting. Like this:

if (url.query.redirectURL)
    dispatch(push('/' + url.query.redirectURL))
DSDmark
  • 1,045
  • 5
  • 11
  • 25