-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
referral query param updates #425
base: master
Are you sure you want to change the base?
referral query param updates #425
Conversation
…y param show up on every item page for logged in users
…y param show up on every item page for logged in users
…om/byoungdale/stacker.news into byoungdale/feature/referral-update
@huumn, I tried to do the url query change in const referralUpdate = props.me ? { r: props.me.name } : {}
router.events.on('routeChangeStart', nprogressStart)
router.events.on('routeChangeComplete', nprogressDone)
router.events.on('routeChangeError', nprogressDone)
if (!props?.apollo) return
// HACK: 'cause there's no way to tell Next to skip SSR
// So every page load, we modify the route in browser history
// to point to the same page but without SSR, ie ?nodata=true
// this nodata var will get passed to the server on back/foward and
// 1. prevent data from reloading and 2. perserve scroll
// (2) is not possible while intercepting nav with beforePopState
router.replace({
pathname: router.pathname,
query: { ...router.query, nodata: true, ...referral }
}, router.asPath, { ...router.options, shallow: true }).catch((e) => {
// workaround for https://github.com/vercel/next.js/issues/37362
if (!e.cancelled) {
console.log(e)
throw e
}
}) The issue is this didn't update the url at all. Then I tried the below in router.events.on('routeChangeStart', nprogressStart)
router.events.on('routeChangeComplete', nprogressDone)
router.events.on('routeChangeError', nprogressDone)
if (!props?.apollo) return
// HACK: 'cause there's no way to tell Next to skip SSR
// So every page load, we modify the route in browser history
// to point to the same page but without SSR, ie ?nodata=true
// this nodata var will get passed to the server on back/foward and
// 1. prevent data from reloading and 2. perserve scroll
// (2) is not possible while intercepting nav with beforePopState
router.replace({
pathname: router.pathname,
query: { ...router.query, nodata: true }
}, router.asPath, { ...router.options, shallow: true }).catch((e) => {
// workaround for https://github.com/vercel/next.js/issues/37362
if (!e.cancelled) {
console.log(e)
throw e
}
})
if (props.me) {
router.push({
pathname: router.pathname,
query: { ...router.query, r: props.me.name },
});
}
`` |
The second argument is what you want to modify. Here's a link to the nextjs docs for router.push (same args with same meanings as router.replace but it has more thorough param descriptions ... you'll still want to use router.replace): https://nextjs.org/docs/pages/api-reference/functions/use-router#routerpush |
Gotcha. Thank you. Should of looked a little closer at the code and docs. Got it working now with router.replace in |
Thanks for this! You did a really precise job of making these changes and I probably would've procrastinated doing this forever otherwise. Please drop a lightning address or something when you get a change so I can tip you when I deploy this. |
Remaining todos:
|
This is for the query param changes for referrals mentioned in #377 .