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

Does Link has 'exact' as a prop? #7526

Closed
lxieyang opened this issue Aug 21, 2018 · 4 comments
Closed

Does Link has 'exact' as a prop? #7526

lxieyang opened this issue Aug 21, 2018 · 4 comments

Comments

@lxieyang
Copy link

I wonder the following words on the readme page from npmjs.org is still true:

Gatsby also supports React Router's props exact, strict, isActive, and location. If any of these props are set, then React Router's NavLink component will be used instead of the default Link.

A bit of a background, what I'd like to do is to build a navbar. Let's say I have:
"/", "/about", "/blogs"
as 3 pages in the app. And if I hit "localhost:8000/blogs", the "/blogs" Links is assigned an "active" attribute. However, if I navigate to a single blog post like "localhost:8000/blogs/what-is-going-on/", then the "/blogs" Link is not "active", which is not an ideal situation.

@LekoArts
Copy link
Contributor

The readme refers to Gatsby v1. Are you using v1 or v2?

@lxieyang
Copy link
Author

Oh, sorry that I wasn't clear enough. I was using v2.

@robinpyon
Copy link
Contributor

V2 is now using reach-router and as such, <Link> no longer has an exact prop.

However you should be able to accomplish what you're after by using reach-router's getProps prop.

From reach-router's documentation:

// this link will be active when itself or deeper routes
// are current
const isPartiallyActive = ({
  isPartiallyCurrent
}) => {
  return isPartiallyCurrent
    ? { className: "active" }
    : null
}

const PartialNavLink = props => (
  <Link getProps={isPartiallyActive} {...props} />
)

Also relevant: https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/#the-following-props-are-no-longer-available-on-link

@lxieyang
Copy link
Author

Thank you!!

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