TanStackT
TanStack2w ago
7 replies
ltd-scarlet

Accessing pathname inside head prop

I’m trying to access the current pathname inside the head prop of createFileRoute.

Right now, I’m doing this as a workaround by inspecting the route matches:

head: ({ matches }) => {
  const route =  matches.find(
    (route) => route.routeId !== "__root__"
  )
...


then use the route

{
  property: "og:url",
  content: `https://example.com${route?.pathname}`,
},


Is there an official or recommended way to access the current pathname inside head?
Was this page helpful?