在 React 中处理登录流程
Handling signin flow in React
我正在尝试在 React 中实现 Last.fm 登录。用户登录 Last.fm 后,他们将被重定向到
http://localhost:3000/loginlanding/?token=${token id goes here}
如何使用 React Router 捕获 url?
到目前为止,我已经尝试了所有这些:
path="/loginlanding/?token:id"
path="/loginlanding/:id"
path="/loginlanding/?:id"
None 其中似乎有效。
基本上,我需要捕获访问令牌并将其存储在全局状态中。
指定路线
<Route path="/loginlanding/:token_id" component={LoginLanding} />
通证
<Link to=`/loginlanding/${token_id}` />
获取令牌
this.props.match.params.token_id
**您可以将您的令牌存储在本地存储中,并在需要时从那里访问它。
或者,如果令牌在父组件中可用,您可以像这样将其作为道具访问。
**
{match:{params:{id}}} //<<<< This can be accessed in the react-router
我正在尝试在 React 中实现 Last.fm 登录。用户登录 Last.fm 后,他们将被重定向到
http://localhost:3000/loginlanding/?token=${token id goes here}
如何使用 React Router 捕获 url? 到目前为止,我已经尝试了所有这些:
path="/loginlanding/?token:id"
path="/loginlanding/:id"
path="/loginlanding/?:id"
None 其中似乎有效。 基本上,我需要捕获访问令牌并将其存储在全局状态中。
指定路线
<Route path="/loginlanding/:token_id" component={LoginLanding} />
通证
<Link to=`/loginlanding/${token_id}` />
获取令牌
this.props.match.params.token_id
**您可以将您的令牌存储在本地存储中,并在需要时从那里访问它。 或者,如果令牌在父组件中可用,您可以像这样将其作为道具访问。 **
{match:{params:{id}}} //<<<< This can be accessed in the react-router