How to properly handle route navigation for new chat? #7089
Replies: 4 comments 4 replies
-
Check out this example https://github.com/vercel/ai/tree/main/examples/next |
Beta Was this translation helpful? Give feedback.
-
Hi @hoanginc144! Could you link/show me your v4 approach (or a minimal repro)? Invoking router.push before submission would actually be quite racy/unreliable. Will dig into this further and share more fleshed out thoughts on your other concerns tomorrow! |
Beta Was this translation helpful? Give feedback.
-
some thoughts on routing:
|
Beta Was this translation helpful? Give feedback.
-
I'm having issues with this on version 5.0.52. I pass a different chat identifier and a new messages array when I call |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to upgrade to V5 for my personal chat app and my implementation of navigation to a /chat/[id] route after first message submission on /chat just broke on V5
My current V4 approach:
With V5 I do the same:
What happens in V5: The message gets submitted, but navigating to the new route resets the messages array and also the stream does not continue (so user just sees a blank screen without any messages).
Note that with V4 even when navigating to the new route the messages array do not get reset and the streaming starts normally. I'm perplexed as how to fix this as it looks like the state of messages is no longer persisted with route change in V5. The reason I don't want to use window.history.replaceState is because I want the user to be able to go back to /chat with the browser back button. Would really appreciate some guidance here, thank you!
Beta Was this translation helpful? Give feedback.
All reactions