我需要在 react js 中的语法帮助,
我希望在路径中实现这样的目标
http://localhost:3000/verify-email?key=ffdffae0237c43e6572bca3a3867eda1&eid=c2Frc2hpN0BnbWFpbC5jb20=
以下代码不起作用
<Route name="businessInformation" exact path="/verify-email?key=:someRandomKey&eid=:someRandomKey"> //Need help here
虽然,这适用于http://localhost:3000/verify-email/:key/:eid
http://localhost:3000/verify-email/:key/:eid
<Route name="businessInformation" exact path="/verify-email/key/eid">
我应该如何附加这样的字符串值以便它理解?
好的,这个问题很不清楚,为了简洁起见,我们假设您要读取查询字符串。这条路线看起来就像:
<Route name="businessInformation" exact path="/verify-email" render={props => <Example {...props}>} />
并且需要读取查询字符串的组件如下所示:
const Example = () => { const { key, eid } = new URLSearchParams(window.location.search) return ( <span>{`key is ${key} and id is ${eid}`}</span> ) }
如果您想导航到这样的路线,那就是:
<Link to={`/verify-email?key${key}&eid=${id}`}/>