How to redirect while preserving the original query param format for example:
Original Query: localhost/login?callback=/shreyas/profile?action=follow
So if want to go register page i used the following code to preserve the callback value, but it somehow converts the ?
, /
& =
symbols, which i don't want to be.
example problem: http://localhost:3000/register?callback=%2Fshreyas%2Fprofile%3Faction%3Dfollow
needed: http://localhost:3000/register?callback=/shreyas/profile?action=follow
Code
const redirectWithCallback = (location) => {
if (router.query && router.query.callback) {
router.push({
pathname: location,
query: {
callback: router.query.callback
},
}, null, { shallow: false })
} else window.location.pathname = location
}