为 nextjs 重定向删除 url 中的参数

removing params in url for nextjs redirect

我有下面的代码。它重定向到 /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}
            });
          }
      });

使用您的示例电子邮件参数,您必须将 dynamic routing and configure your router to push 设置为电子邮件地址。

如果启用浅层路由,则知道它仅适用于 same page URL。设置动态页面后,您可以通过 router.push 导航到它,例如:

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