Smooth Route Transitions in TanStack Router
Hey everyone! I'm working on a chat application with TanStack Router and struggling with achieving smooth transitions between routes without unwanted remounting. Here's my situation:
Current Route Structure:
2 Replies
afraid-scarletOP•4mo ago
The Problem:
When a user starts a new chat on /chat/new, the server returns a new chat ID in the response headers. I want to smoothly transition the URL from /chat/new to /chat/abc123 WITHOUT remounting the component, so animations and state are preserved.
Current Implementation (that doesn't work):
What I've Tried (and why they failed):
Route Masking - Used mask option but the chat never gets the new ID page, stays on new chat page
Shared Component Approach - Single component handling both new/existing, but I DO want remounting when navigating TO /chat/new (for fresh state), just not when transitioning FROM new to existing
Various navigation options - replace: true, resetScroll: false, etc.
Current Route Definitions:
Is there a way in TanStack Router to transition between different route components smoothly without remounting? Or should I be structuring this differently?
I've read about the router previously using route keys that cause remounting, but I need the remounting behavior for new chats, just not for this specific transition.
Any ideas or alternative approaches would be greatly appreciated!
eastern-cyan•4mo ago
can you get into more detail about the shared component approach?
when is it not remounting?
are you maybe looking for remountDeps ?