Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  129] [ 5]  / answers: 1 / hits: 6802  / 3 Years ago, sun, march 7, 2021, 12:00:00

I have a data inside an object in my page. I want to redirect from that page to another page along with the data like the code below


const redirectAppointmentStep1 = (value) => {
router.push({
pathname: '/Appointment/bookingstep1',
query: {value : value},
})
}

and I received that data in bookingstep1 page like this


 const {query} = useRouter()

but the problem is the query appear on the url and the url does not look clean. How can I send the data from one page to another page but without appearing it on the url?


I am new in Next.js so any help will be highly appreciated.


More From » node.js

 Answers
2

If you want to send "route state" you have to do it via query string, but you can actually "mask" the path that is shown in the browser via the as property.


Router.push



router.push(url, as, options)

as - Optional decorator for the URL that will be shown in the
browser.



You can decorate the URL to match the path name.


const redirectAppointmentStep1 = (value) => {
router.push(
{
pathname: '/Appointment/bookingstep1',
query: {value : value},
},
'/Appointment/bookingstep1', // "as" argument
)
}

[#1683] Monday, March 1, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
;