Skip to content

Docs: router.push and typedRoutes makes no mention of type requirements #83109

@neilenns

Description

@neilenns

What is the documentation issue?

https://nextjs.org/docs/app/api-reference/config/typescript#statically-typed-links
https://nextjs.org/docs/app/api-reference/functions/use-router

Neither of these pages mention that if you enabled typedRoutes that router.push() also does route checking, and attempting to use constructed strings like this will result in a build error:

router.push(`${baseUrl}${filterValue}`);

Is there any context that might help us understand?

The way I fixed this was to cast the string to type Route:

import type { Route } from "next";

...

router.push(`${baseUrl}${filterValue}` as Route);

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/functions/use-router

Metadata

Metadata

Assignees

Labels

ImprovementReport possible improvements to make in our documentationlocked

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions