T
TanStack5mo ago
extended-salmon

How to match location with fullpath in beforeLoad method

Here https://stackblitz.com/edit/tanstack-router-wryvvkja?file=src%2Froutes%2F_appLayout.tsx I am currently in a situation where i need to match a pathname (i.e "/patients/agnes_smithson-132/diagnostic-history") with "/patients/$patient_slug/diagnostic-history". Please all these are dynamic as it is in the above code. Using router.routeByPath, i get all routes object, is it possible to use location to match the current route from the routes object.
Chigoziem Nwaiwu
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
3 Replies
extended-salmon
extended-salmonOP5mo ago
The major thing i need here is how best to access the current route RouteOptions Thanks guys ... router.getMatchedRoutes(location)?.foundRoute did the magic.
foreign-sapphire
foreign-sapphire5mo ago
thats not necessary though you get the matches in there already
beforeLoad: ({ matches }) => {
console.log(matches[matches.length - 1].routeId);
},
beforeLoad: ({ matches }) => {
console.log(matches[matches.length - 1].routeId);
},
extended-salmon
extended-salmonOP5mo ago
woooooow ... Thanks

Did you find this page helpful?