T
TanStack7mo ago
genetic-orange

changing URL without triggering a navigation

I'm having a very hard time getting this to work: - I have a route /chat where after I submit a form I'd like to update the URL to /chat/{id created client side} but NOT trigger a navigation to the /chat/{id} route - In my form submission handler I've tried: - window.replaceState - useNavigate with replace: true Neither of these things work. I still see the /chat/{id} loader + component get hit. Would really appreciate some help here!
5 Replies
unwilling-turquoise
unwilling-turquoise7mo ago
that's not possible. changing the URL causes a navigation why would you not want that?
genetic-orange
genetic-orangeOP7mo ago
the submission of the form POSTs to a server endpoint that streams back events
unwilling-turquoise
unwilling-turquoise7mo ago
some more details please
genetic-orange
genetic-orangeOP7mo ago
it's a pretty vanilla AI SDK useChat + POST /chat endpoint. User loads /chat and we create a chat ID client side. When they submit the first message the AI SDK POSTs to /chat which then starts streaming back the LLM outputs we store chats in a db w/ an id so that they each get a permalink /chat/{id}. I'd like for that to be the new URL once they submit the form open to suggestions for how to do this but my ideal setup is one where the only things I see in the network tab are GET /chat, then POST /api/chat and nothing else, and the URL updates to /chat/${id} but right now it's hitting all the logic for the /chat/${id} route open to suggestions / workarounds / different approaches that are easier to accomplish w/ start i'm guessing the easier approach would be to have the initial message / first form submit hit a server function that does all the creation of the chat in our database and redirects to /chat/{id} which then POSTs to /api/chat and starts streaming back responses
unwilling-turquoise
unwilling-turquoise7mo ago
that could be a valid solution yes

Did you find this page helpful?