Replies: 80 comments 21 replies
-
Currently that's not possible and I don't think we'll support it immediate future. |
Beta Was this translation helpful? Give feedback.
-
But let's open this and see whether we really really need this. |
Beta Was this translation helpful? Give feedback.
-
I think you should do this by passing query parameters. |
Beta Was this translation helpful? Give feedback.
-
I mean you can achieve a similar thing by passing in query parameters like nkzawa said, but I'd rather not pollute my the url with |
Beta Was this translation helpful? Give feedback.
-
You can use |
Beta Was this translation helpful? Give feedback.
-
Well I suppose so, but if I were to use I'm porting over a project to next.js and haven't run into any major compatibility problems since I found ways to refactor codes to make it work, it's just inconvenience and verbosity at this point that can be improved and all this issue is. Thanks all for your input. |
Beta Was this translation helpful? Give feedback.
-
Closing this cause of inactivity 👍 |
Beta Was this translation helpful? Give feedback.
-
A little over a year since I brought this up, but is this still not supportable? |
Beta Was this translation helpful? Give feedback.
-
You can save any required state in localStorage, sessionStorage, a variable, a Redux store, etc. and then use it in getInitialProps (checking you are running client side). |
Beta Was this translation helpful? Give feedback.
-
i think nextjs should start supporting react-router |
Beta Was this translation helpful? Give feedback.
-
I want same functionality. Earlier I was using CRA and there I used to send state to routed component. I wants same functionality with nextjs. What @sergiodxa suggested in workaround but library support will be good. |
Beta Was this translation helpful? Give feedback.
-
Same here, would be great if it will be possible pass data with |
Beta Was this translation helpful? Give feedback.
-
I want same functionality. Any update on this ? |
Beta Was this translation helpful? Give feedback.
-
me too |
Beta Was this translation helpful? Give feedback.
-
Another question related to this issue is:
|
Beta Was this translation helpful? Give feedback.
-
So, is this issue even being considered? |
Beta Was this translation helpful? Give feedback.
-
An bad idea but probably the only way to get around this annoying issue. Is to override the This is just pseudo code needs also injecting into const methods = ["back", "forward", "go", "pushState", "replaceState"];
const proxy = Object.fromEntries(methods.map((key) => [key, history[key]]))
history.back = function back(...args) {
// modify args...
return proxy.back.apply(this, args);
};
history.forward = function forward(...args) {
// modify args...
return proxy.forward.apply(this, args);
};
history.go = function go(...args) {
// modify args...
return proxy.go.apply(this, args);
};
history.pushState = function pushState(...args) {
// modify args...
return proxy.pushState.apply(this, args);
};
history.replaceState = function replaceState(...args) {
// modify args...
return proxy.replaceState.apply(this, args);
}; Keep Next.js history states seperate. Then we should be able to at least keep state in history. history.state: {
nextState: {
// here is namespace for all next.js history states.
},
appState: {
// here is namespace for your app history states.
}
} If there are some helper functions that prevents app history state only to affect that app state than it should be fine. References: |
Beta Was this translation helpful? Give feedback.
-
It would be fine if I could use Link
^ I'm not able to get the query param relatedPost on |
Beta Was this translation helpful? Give feedback.
-
what if i am redirecting my page to new page on new tab still it will work or not |
Beta Was this translation helpful? Give feedback.
-
any solution? 💀 |
Beta Was this translation helpful? Give feedback.
-
This is working |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
With the AppRouter, you can now use native Looks like they added experimental support for using the native history API in v14.0.3 and I'm guessing it landed as stable sometime after that since the docs don't say it's experimental. Here's the original PR #58335 so you can read through it to see if any of the tradeoffs affect you. |
Beta Was this translation helpful? Give feedback.
-
Thanks @BenEinwechter. I tested this feature out but it seems pretty useless since for client-side navigation it always overwrites history.state immediately. It ought to extend the user-supplied history.state rather than replacing it. |
Beta Was this translation helpful? Give feedback.
-
No, I wasn't able to find any workaround except for forcing my state into
the URL, which is recommended by next I guess, but I don't consider this a
good solution.
Le mer. 13 mars 2024, 5 h 21 a.m., danbru ***@***.***> a
écrit :
… Did u find any solution to this? Same problem here @benwiley4000
<https://github.com/benwiley4000>
—
Reply to this email directly, view it on GitHub
<#23991 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADHOD3KAS4V43J5MSYGJPSLYYALAHAVCNFSM423FYRE2U5DIOJSWCZC7NNSXTOKENFZWG5LTONUW63SDN5WW2ZLOOQ5TQNZXGAYTSMA>
.
You are receiving this because you were mentioned.Message ID: <vercel/next
.***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I ran into this issue today and wanted to share a more "Reacty" work around I ended up going with that allows for passing around arbitrarily complex objects. The basic idea is to use the React context to pass whatever objects we want around. The full code for what I did is here. For those facing this problem looking for a solution that uses traditional React tools/hooks, the context provider is below:
I added this provider at
|
Beta Was this translation helpful? Give feedback.
-
I am having the same problem and am migrating from react-router. useRouter as a client component should have state functionality and be client focused. |
Beta Was this translation helpful? Give feedback.
-
If you have an option to stick with react router I wouldn't migrate to next
router, especially if you're relying on history state.
Le lun. 18 mars 2024, 4 h 10 a.m., birddle ***@***.***> a
écrit :
… I am having the same problem and am migrating from react-router. useRouter
as a client component should have state functionality and be client focused.
—
Reply to this email directly, view it on GitHub
<#23991 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADHOD3KNET3ZZDJC4FMQI63YY2OOLAVCNFSM423FYRE2U5DIOJSWCZC7NNSXTOKENFZWG5LTONUW63SDN5WW2ZLOOQ5TQOBSGQZTOMI>
.
You are receiving this because you were mentioned.Message ID: <vercel/next
.***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Does this means we will have to impose redux for passing a single state? |
Beta Was this translation helpful? Give feedback.
-
Bhai upi krta 100 INR, krde yaar |
Beta Was this translation helpful? Give feedback.
-
With react-router I was able to do:
browserHistory.push({ pathname: "/", state: { message: 'This is a message forwarded in a state.' } })
Is it possible to do something like this using next/router or a way to redirect the user and also pass some value over to the new page?
Beta Was this translation helpful? Give feedback.
All reactions