Next.js Discord

Discord Forum

Typesafe usePathname?

Unanswered
Dwarf Crocodile posted this in #help-forum
Open in Discord
Dwarf CrocodileOP
Hey all, Powder here.

I've been using the experimental config option typesafeRoutes for a good bit now and it's been a great experience. It works with both the <Link /> component and the useRouter() hook.

However, I was wondering if it's possible to have it work with usePathname() as well?

1 Reply

Dwarf CrocodileOP
My current implementation of making it work is using some type casting.

const pathname = usePathname() as LinkProps<string>["href"] | (string & {});


And while this works how I'd like it to, i would prefer a more "native" solution.