Next.js: How to get separate multiple query data?

Created on 20 Jul 2017  路  3Comments  路  Source: vercel/next.js

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Context

I'm tying to get multiple query data. I came up with this before redirect:

Router.push('/acceptance/procurement/RejectedInfo?procurementUUID=0ae56414-0699-4866-898d-be41ab146523?acceptanceUUID=24ecb437-8e52-48f1-82f8-d5d7fb1d22b7');

which mean there is 2 query param:
procurementUUID=0ae56414-0699-4866-898d-be41ab146523 and
acceptanceUUID=24ecb437-8e52-48f1-82f8-d5d7fb1d22b7'

but in my props, both query is merged with procurementUUID
image

How can I separate procurementUUID and acceptanceUUID value?

Thanks in advance.

Most helpful comment

This is basic HTML query resource manipulation. You learned how to do it by passing a object to Router, but it is worth pointing out that you were close with the string solution also.

'/acceptance/procurement/RejectedInfo?procurementUUID=0ae56414-0699-4866-898d-be41ab146523&acceptanceUUID=24ecb437-8e52-48f1-82f8-d5d7fb1d22b7'

You only have 1 question mark in query params, and that denotes the start of the query. Every property then follows key=value with a & joining multiple into the same query.

domain.com?key1=valueA&key2=valueB&key3=valueC

The object you found in the docs is the preferred way when using the Router for sure. But it's good to know what it is actually building behind the scenes.

All 3 comments

This is how you do it:

Router.push({ pathname: '/acceptance/procurement/RejectedInfo', query: { procurementUUID: '0ae56414-0699-4866-898d-be41ab146523', acceptanceUUID: '24ecb437-8e52-48f1-82f8-d5d7fb1d22b7' } });

image

It's clearly written in the docs. :p

This is basic HTML query resource manipulation. You learned how to do it by passing a object to Router, but it is worth pointing out that you were close with the string solution also.

'/acceptance/procurement/RejectedInfo?procurementUUID=0ae56414-0699-4866-898d-be41ab146523&acceptanceUUID=24ecb437-8e52-48f1-82f8-d5d7fb1d22b7'

You only have 1 question mark in query params, and that denotes the start of the query. Every property then follows key=value with a & joining multiple into the same query.

domain.com?key1=valueA&key2=valueB&key3=valueC

The object you found in the docs is the preferred way when using the Router for sure. But it's good to know what it is actually building behind the scenes.

Thank you. It's really helpful. :)

Was this page helpful?
0 / 5 - 0 ratings