How to know dynamic router.pathname in app router version #61846
Replies: 4 comments 3 replies
-
Hii! Have you tried to use the instance // /middleware.ts
import { NextResponse } from 'next/server';
export function middleware(request: Request) {
// Store current request url in a custom header, which you can read later
const requestHeaders = new Headers(request.headers);
requestHeaders.set('x-server-url', request.url);
return NextResponse.next({
request: {
// Apply new request headers
headers: requestHeaders,
}
});
} |
Beta Was this translation helpful? Give feedback.
-
how this is not solved officially? Is there a different pattern that I am missing maybe? |
Beta Was this translation helpful? Give feedback.
-
its almost impossible to create dynamic breadcrumbs without an ability to get route name lol |
Beta Was this translation helpful? Give feedback.
-
lol still not solved. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to migrate a web application from Next.js page routing to app routing, but I've encountered a problem. In the _app.tsx file, I can't determine the original pathname in dynamic routes. For example, if I have this structure in the pages directory:
In the _app.tsx file's getInitialProps method, I receive the router object, and router.pathname gives me "[category]" instead of the actual category like 'dynamicCategory/...'.
For the app routing version:
Is there a way in the app routing version to get these original pathnames inside layouts or pages on the server side? I know that usePathName() exists, but the response from this hook (which can only be used on the client side) is the calculated route, not the original dynamic route (i.e., the pathname inside the brackets [category]).
I've been trying to get this dynamic route from the middleware, but I haven't been successful.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions