revalidatePath(), redirect() and <Link> without using strings? #66334
DamienCassou
started this conversation in
Ideas
Replies: 1 comment
-
I initially asked the same question on https://nextjs-forum.com/post/1245377842120888411 and was redirected here. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
revalidatePath()
,redirect()
and<Link>
Non-Goals
No response
Background
The functions
revalidatePath()
(fromnext/cache
) andredirect()
(fromnext/navigation
) take a string as argument. For example (from the official tutorial):The string as argument is a bit annoying because it means duplicating the paths in many places of the application without any refactoring support. Also, there is absolutely no validation that the path actually exists. The problem is the same for
Link
(fromnext/link
).Proposal
Would it be possible to pass a
Page
component instead? Something like:This is not a final solution (e.g., "@/app/dashboard/invoices/[id]/edit/page.tsx" isn't enough to know which invoice "id" should be used) but just an idea. Given that Next.js already knows how to map files to routes, I guess something like that should be possible to implement.
I have no idea how this feature could be implemented. I'm not even sure if it's a good idea. But I think the problem is real and the suggested idea makes sense.
I would be happy implementing this (this would be my first contribution).
Beta Was this translation helpful? Give feedback.
All reactions