Juliette
Juliette

Reputation: 4439

removing params in url for nextjs redirect

I have the code below. It redirects to /home and passes a email var. However, in the address bar, it shows http://localhost:4000/[email protected]. How can I pass variables using react and next.js cleanly?

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}
            });
          }
      });

Upvotes: 0

Views: 856

Answers (1)

Sean W
Sean W

Reputation: 6628

Using your example email param, you have to setup dynamic routing and configure your router to push as the email address.

If you enable shallow routing know that it only works for the same page URL. After you set up your dynamic page you'd navigate to it via router.push like:

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

Upvotes: 1

Related Questions