我正在尝试在 React 中实现 Last.fm 登录。用户登录到 Last.fm 后,他们将被重定向到
http://localhost:3000/loginlanding/?token=${token id goes here}
如何使用 React 路由器捕获网址? 到目前为止,我已经尝试了所有这些:
path="/loginlanding/?token:id"
path="/loginlanding/:id"
path="/loginlanding/?:id"
这些似乎都不起作用。 基本上,我需要捕获访问令牌并将其存储在全局状态中。
指定路由
<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