Skip to content
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

anchor was not added to correct path #51

Closed
xilibro opened this issue Jan 9, 2019 · 2 comments
Closed

anchor was not added to correct path #51

xilibro opened this issue Jan 9, 2019 · 2 comments

Comments

@xilibro
Copy link

xilibro commented Jan 9, 2019

My page url is : http://localhost:8080/#/component/srclock
but the anchor link is : http://localhost:8080/#/ji-chu-yong-fa

'component/srclok' part gone .

What problem is it would be? Who can give me some tips。

@valeriangalliat
Copy link
Owner

Hi! This is because by default markdown-it-anchor sets the href of the title anchor to #slug, meaning that if your slug is ji-chu-yong-fa, the href will be #ji-chu-yong-fa. The browser will then replace the whole anchor part of the URL, losing the /components/srclock part.

This is the default way of browsers to link to a specific element of the page. If you use the anchor part of the URL for internal navigation purpose, you can't use anchors to link to specific element of the page, and you would need to re-implement this behavior yourself.

For example, you could can pass a custom permalinkHref function that would keep the /components/srclock par of the URL and append the slug to it, so you would end up with something like #/components/srclock#ji-chu-yong-fa. It's then your responsibility to have some code parsing the location.hash to extract the ji-chu-yong-fa part at the end and make the browser scroll tho the element that have this ID.

@nagaozen
Copy link
Collaborator

@valeriangalliat is right, it's not an issue. The solution involves passing a custom permalinkHref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants