Handling signin flow in React

Viewed 65

I'm trying to implement Last.fm signin in React. After the user logins to Last.fm, they are redirected to

http://localhost:3000/loginlanding/?token=${token id goes here}

How do I capture the url using React Router? So far, I have tried all these:

path="/loginlanding/?token:id"
path="/loginlanding/:id"
path="/loginlanding/?:id"

None of these seem to work. Basically, I need to capture the access token and store it in global state.

2 Answers

specify route

<Route path="/loginlanding/:token_id" component={LoginLanding} />

pass token

<Link to=`/loginlanding/${token_id}` />

get token

this.props.match.params.token_id

**you can store your token in the localstorage and access it from there whenever needed. Or if the token is available in the parent component you can access it as a prop like this. **

    {match:{params:{id}}} //<<<< This can be accessed in the react-router  
Related