T
TanStack7mo ago
ambitious-aqua

Get fullPath and params from interpolated pathname

Hey everyone, is there a utility exported from tanstack that would be able to tell me based on a list of routes and a pathname, which route said pathname matches? Something like
function findMatch(routes: string[], pathname: string): string

const routes = [
'/_auth/foo/bar',
'/foo/$kind',
]
findMatch(routes, '/foo/bar') // '/_auth/foo/bar'
function findMatch(routes: string[], pathname: string): string

const routes = [
'/_auth/foo/bar',
'/foo/$kind',
]
findMatch(routes, '/foo/bar') // '/_auth/foo/bar'
My use-case (right now, but there are probably more) is for code ownership attribution during end-to-end testing, I have the list of routes (from the manifest at the bottom of the routeTree.gen) and the URL where the error happened, and I'd like to match those 2 together. --- If this doesn't exist for an arbitrary list of routes, does it exist with a router? Something link router.findMatch('/foo/bar') // '/_auth/foo/bar'
1 Reply
fair-rose
fair-rose7mo ago
router.matchRoutes() ?

Did you find this page helpful?