S
SolidJS16mo ago
Jérémy

Is there a way to hook into the router's match (client)?

Is there a way to hook into the router (client-side) to override router.location in the <Routes> component? I want to alter the matched route that I rewrote on the server using a middleware.
export const Routes = (props: RoutesProps) => {
const router = useRouter();
const parentRoute = useRoute();
const routeDefs = children(() => props.children) as unknown as () =>
| RouteDefinition
| RouteDefinition[];
const branches = createMemo(() =>
createBranches(routeDefs(), joinPaths(parentRoute.pattern, props.base || ""), Outlet)
);
const matches = createMemo(() => getRouteMatches(branches(), router.location.pathname));
//...
export const Routes = (props: RoutesProps) => {
const router = useRouter();
const parentRoute = useRoute();
const routeDefs = children(() => props.children) as unknown as () =>
| RouteDefinition
| RouteDefinition[];
const branches = createMemo(() =>
createBranches(routeDefs(), joinPaths(parentRoute.pattern, props.base || ""), Outlet)
);
const matches = createMemo(() => getRouteMatches(branches(), router.location.pathname));
//...
2 Replies
mdynnl
mdynnl16mo ago
you can through <Router source={...} />
Jérémy
Jérémy15mo ago
Thanks. Hmm… would you have an example of usage?