You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! It is possible to use the link component in some way, outside the <RouterProvider /> that matches the routes?
I tried
import{RouterProvider,createRouter,Link,RouterContextProvider,typeLinkComponent}from"@tanstack/react-router";import{routeTree}from"./routeTree.gen";exportconstmodalRouter=createRouter({ routeTree });exportfunctionModal(){return<RouterProviderrouter={modalRouter}/>;}exportconstModalLinkFromOutside: LinkComponent<"a">=(props)=>{return(<RouterContextProviderrouter={modalRouter}><Link{...props}/></RouterContextProvider>);};exportfunctionMinimalExample(){// The goal it to render something like this in Astro:return(<><Modal/><ModalLinkFromOutsideto="/open">Open modal</ModalLinkFromOutside></>);}
and got Invariant failed: Could not find the nearest match! when the ModalLinkFromOutside is rendered.
Why I am doing this? I want to build a static site in Astro with FULL client side navigation in a modal (don't ask the server needed HTML/JS on navigation in it). The router layer is only added to the modal, and links outside the modal should open it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi! It is possible to use the link component in some way, outside the
<RouterProvider />
that matches the routes?I tried
and got
Invariant failed: Could not find the nearest match!
when theModalLinkFromOutside
is rendered.Why I am doing this? I want to build a static site in Astro with FULL client side navigation in a modal (don't ask the server needed HTML/JS on navigation in it). The router layer is only added to the modal, and links outside the modal should open it.
Beta Was this translation helpful? Give feedback.
All reactions