-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link with hash doesn't seem to work in next13 #42157
Comments
This is also happened for me |
I don't want to hijack your thread, but I found another issues with hashes in links.
Update: this is working now. |
I also have run into this issue, next/link is not appending the hash to the url and instead is routing to the hash address. |
Adding shallow={true} worked for me: Go there |
Does not work in |
Anyone figured it out yet. I am stilling facing this issue in |
I am facing this issue too with next@13.1.2 |
For now, I am using the raw HTML |
Having this as well, next@13.3. Using tags at the moment to workaround. |
Next 13.4.2, still issues with |
"next": "13.4.3"
Does anyone know how to get this '#id' part from the url ? |
Sorry if this isn't the right place, but I'm seeing the following issue using
guessing this is some sort of uncleared state issue? My workaround currently is to add an id to the top element of my root route and have links go to |
For me link with # works but general link not navigating |
Like is not working in next js 13.4.2 |
some code reference would help everyone to understand your problem better.
which takes you to about page. Then you need to put about folder inside app directory. file structure should be like this
the "/" indicates app route or folder then about directs to your about folder and page.js/tsx/jsx renders about page. You can switch /about with /blog to go to blog page. |
…r push/replace (#49521) ## Problem Relative hash/query handling in `next/link` (e.g. `<Link href="#hello">`) is broken in App Router, especially if you're on a nested route. This wasn't a problem in `/pages` because the href always get fully resolved in `<NextLink>`; i.e. if you have `<Link href="#hash" />` on `/hello`, it'll resolve the href to `/hello#hash` and use that everywhere. However, in App Router, `<Link>` no longer uses the current location to resolve the href: https://github.com/vercel/next.js/blob/5451564f364399003b05939fa6dd7d32c1dabec7/packages/next/src/client/link.tsx#L450-L457 Therefore navigating with `new URL(href, location.origin)` will skip the current path and always apply the relative hash/query to the _root_ route: https://github.com/vercel/next.js/blob/5451564f364399003b05939fa6dd7d32c1dabec7/packages/next/src/client/components/app-router.tsx#L208-L215 ## Solution Not 100% sure if this is the best solution, but since `app-router` is already reading `window.location`, I'm using `location.href` as the base URL to resolve the href. I grep'd for `location.origin` and checked other callsites; seems like only `app-router` deals with user specified hrefs. Fixes #42157 & #44139, and potentially #48554 and #22838 ## Test Plan ``` pnpm testheadless test/e2e/app-dir/navigation ``` ---------
…r push/replace (vercel#49521) ## Problem Relative hash/query handling in `next/link` (e.g. `<Link href="#hello">`) is broken in App Router, especially if you're on a nested route. This wasn't a problem in `/pages` because the href always get fully resolved in `<NextLink>`; i.e. if you have `<Link href="#hash" />` on `/hello`, it'll resolve the href to `/hello#hash` and use that everywhere. However, in App Router, `<Link>` no longer uses the current location to resolve the href: https://github.com/vercel/next.js/blob/5451564f364399003b05939fa6dd7d32c1dabec7/packages/next/src/client/link.tsx#L450-L457 Therefore navigating with `new URL(href, location.origin)` will skip the current path and always apply the relative hash/query to the _root_ route: https://github.com/vercel/next.js/blob/5451564f364399003b05939fa6dd7d32c1dabec7/packages/next/src/client/components/app-router.tsx#L208-L215 ## Solution Not 100% sure if this is the best solution, but since `app-router` is already reading `window.location`, I'm using `location.href` as the base URL to resolve the href. I grep'd for `location.origin` and checked other callsites; seems like only `app-router` deals with user specified hrefs. Fixes vercel#42157 & vercel#44139, and potentially vercel#48554 and vercel#22838 ## Test Plan ``` pnpm testheadless test/e2e/app-dir/navigation ``` ---------
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Brave 106.0.5249.119
How are you deploying your application? (if relevant)
next dev
Describe the Bug
Linking with hash doesn't seem to work in next13
becomes
http://localhost:3000/undefined#footer
Expected Behavior
link should be to current page header but instead becomes
http://localhost:3000/undefined#footer
Link to reproduction
https://codesandbox.io/p/github/shanejonas/nextjs-link-undefined-bug/draft/great-lake?file=%2Fapp%2Fpage.tsx
To Reproduce
click/hover over
Link To Footer
to see the link hasundefined
in itScreenshot
The text was updated successfully, but these errors were encountered: