Repository navigation
Replies: 5 comments
|
Use a plain For # .env.local
NEXT_PUBLIC_BASE_PATH=/docs// next.config.mjs
export default {
basePath: process.env.NEXT_PUBLIC_BASE_PATH ?? '',
};Then a Server Component can render an ordinary anchor: // app/page.tsx
export default function Page() {
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? '';
return <a href={`${basePath}/about`}>About</a>;
}This produces Use your existing prefix instead of References: Link behavior, basePath, public environment variables. |
|
In Next.js, If you specifically need a full-page navigation, you can use a regular HTML anchor ( Before changing the navigation approach, could you share a minimal example of your |
|
A regular HTML anchor ( For example: If your app uses Also, A plain anchor is the simplest solution when a full page reload is required. |
This comment was marked as spam.
This comment was marked as spam.
|
One thing worth checking here is whether the path prefix is coming from If it's the configured The tricky part is if your middleware is calculating a different prefix per request. Are you using a fixed That would help narrow down whether you just need a normal anchor with the correct URL or a way to construct that URL per request. Docs: https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath |
Uh oh!
There was an error while loading. Please reload this page.
Summary
When you click on an A tag rendered with a Link tag, a javascript-based differential screen change occurs instead of normal page navigation.
Please tell me how to disable this and perform normal page navigation.
I also tried setting prefetch to false, but this is a completely different function.
I would like to write a normal A tag directly in jsx instead of a Link tag, but I can't do this because I need to add middleware to get the basePath from server components.
Additional information
No response
Example
No response
All reactions