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

Hashtag doesn't change on current page #38

Open
konstantinschuette opened this issue Mar 28, 2021 · 1 comment
Open

Hashtag doesn't change on current page #38

konstantinschuette opened this issue Mar 28, 2021 · 1 comment

Comments

@konstantinschuette
Copy link

konstantinschuette commented Mar 28, 2021

Hello,

so I got these two files with the AnchorLink setup properly.

index.js

import * as React from "react"
import { Link } from "gatsby"
import { StaticImage } from "gatsby-plugin-image"

import Layout from "../components/layout"
import SEO from "../components/seo"
import { AnchorLink } from "gatsby-plugin-anchor-links"

const IndexPage = () => (
  <Layout>
    <SEO title="Home" />

    <AnchorLink to="/#test">got to #test</AnchorLink>
    <div style={{ marginTop: 800 }}></div>
    <div id="test">test</div>

    <Link to="/page-2/">Go to page 2</Link>
    <Link to="/using-typescript/">Go to "Using TypeScript"</Link>
  </Layout>
)

export default IndexPage

page-2.js

import * as React from "react"
import { Link } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"

const SecondPage = () => (
  <Layout>
    <SEO title="Page two" />
    <Link to="/#test">Go back to #test</Link>
  </Layout>
)

export default SecondPage

Now if I'm on my Index page, I want that if i click on <AnchorLink to="/#test">got to #test</AnchorLink> that the hashtag gets added to the URL. The default behavior is, that it just scrolls to to #test, but doesn't add the hashtag to the link.
How can I archive that?

@brohlson
Copy link
Owner

For now, you can pass your own custom function as onAnchorLinkClick. Feel free to put up a PR if it's something you'd like added to the lib!

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

2 participants