How do I use the 'as' props for Link in the new App Router #50709
-
|
Hi, I'm trying to use the link 'as' to fake the url when the user click on the link, just like I usually did on the pages router. But it doesn't work as expected anymore. '<Link It keeps directing the page to the 'as' url not the actual 'href'. Did I do something wrong or do I have to go a different way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The feature you are looking for can be resolved by using the
Since the
Example: // middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
// do something here to get the ${list.toLowerCase()} value and ${index} value
return NextResponse.redirect(new URL('/your desired URL', request.url));
}
// See "path-to-regexp" below to learn more
export const config = {
matcher: '/dynamic-route-path/:path*',
};
Note that
Reference
|
Beta Was this translation helpful? Give feedback.
The feature you are looking for can be resolved by using the
middleware.Since the
middlewareruns before a request is completed, it is possible toredirectto the URL bypathnamewhich was directed by theLinkcomponent.Example: