正在为nextjs重定向删除url中的params



我有下面的代码。它重定向到/home并传递一个电子邮件变量。然而,在地址栏中,它显示http://localhost:4000/home?email=steverodgers@gmail.com。如何使用react和next.js干净地传递变量?

import { withRouter } from 'next/router'
authenticateUser(this.user)
.then(response => {
var email = response['email'];
if (email) {
this.props.router.push({
pathname: '/home',
query: { email: email}
});
}
});

使用示例电子邮件参数,您必须设置动态路由并将路由器配置为推送电子邮件地址。

如果您启用浅路由,请知道它只适用于相同的页面URL。在你设置好动态页面后,你会通过router.push导航到它,比如:

router.push('home/[email]', `/home/${email}`);

最新更新