grabury
grabury

Reputation: 5599

Why is my nextjs router not return query params?

When I navigate to http://localhost:3000/users/123?foo=bar of my nextjs app I get the following when I print out router.query

{id: "123"}

What could be the reasons it is not adding foo: 'bar' to the query object?

Upvotes: 2

Views: 2292

Answers (2)

grabury
grabury

Reputation: 5599

I had to add a next.config.js file with the following

module.exports = {
  reactStrictMode: true,
  async rewrites() {
    return [
      {
        source: '/pages/:slug*',
        destination: '/:slug*'
      }
    ]
  }
}

Upvotes: -1

ven
ven

Reputation: 304

Your file layout should look like this:

pages/
  users/
   [id].js

Having just tested this, the returned query object is {"foo":"bar","id":"123"}.

Upvotes: -1

Related Questions