Router Base Attribute does break hash links
See original GitHub issueVersion
@nuxt/content: 1.5.3 nuxt: 2.14.0
Reproduction Link
https://codesandbox.io/s/autumn-https-x3oxj?file=/nuxt.config.js
You need do change the demo browser window to the subfolder https://x3oxj.sse.codesandbox.io/test/
Steps to reproduce
Set base attribute inside nuxt.config.js
router: {
base: "/test"
},
Go to the about
page and click on the footnote. You will the URL changing to the hash but removing the current page about
. This does also happening with the other types of hash routes on the same page, eg. headings or content links.
What is Expected?
Hash should be added to current page url.
What is actually happening?
Hash will remove the current Url and will be added to the base.
PS: On discord I made a video and gif of the problem, because I’m trying to deploy my nuxt-content page inside a subfolder.
Cheers Hannes
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Vue.js - How to remove hashbang #! from url? - Stack Overflow
To get rid of the hash, we can use the router's history mode, which leverages the history.pushState API to achieve URL navigation without...
Read more >5 Remarkable React Router Features (Anchor Links, Query ...
Dynamic Solution (Hooks). A much better solution is to leverage the url property from the match object that each <Route /> has.
Read more >Ultimate React Router v6 Guide
React Router is by far the most popular routing library in React and this article goes in depth on everything you need to...
Read more >Hash in history mode router, breaks URL : r/vuejs - Reddit
Using Vue 2.6.14, Vue Router set to history mode, URL containing a hashtag "#" breaks dynamic path. const router = new VueRouter({ base…...
Read more >Dealing with links in Next.js - LogRocket Blog
My first technique is wrapping the Link component. Every routing library has a similar component; it is used instead of the <a> tag....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This https://github.com/nuxt/content/issues/376#issuecomment-702193217 almost worked for me, except for the images as @b1rdhous3 pointed out.
This is how I solved that part:
In
nuxt.config.js
Nuxt masks this issue by adding a redirect rule from / from base in dev env, so unless you build and test the generated bundle you won’t find this issue until it’s deployed to prod. Might be a good idea to not add those redirects, but that’s for upstream.
Hi there,
When using
router.base
, Nuxt adds a<base href="/test/">
.Sadly it looks like a known issue from the browser: https://rogerkeays.com/blog/using-base-href-with-anchors
You can use a Nuxt hook to remove the
<base>
tag, actually it fixes your issue but may introduces somes issues (you will have to check to make sure your websites works perfectly without it):Working sandbox: https://codesandbox.io/s/green-meadow-tquyq?file=/nuxt.config.js:838-1027