[gatsby-plugin-react-next] <Link>'s activeClassName not respected, when pathPrefix is used
See original GitHub issueDescription
When using gatsby-plugin-react-next
and pathPrefix
, activeStyle
or activeClassName
are not taken into account when page is initial loaded. Only after manual triggering navigation, activeStyle
or activeClassName
are respected.
Environment
Gatsby version: 1.9.135 Node.js version: 8.7.0 Operating System: macOS 10.13.2
File contents (if changed):
gatsby-config.js
:
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
},
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-plugin-react-next`,
],
pathPrefix: `/my-gatsby-site`,
}
package.json
:
{
"name": "gatsby-starter-default",
"description": "Gatsby default starter",
"version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"gatsby": "^1.9.135",
"gatsby-link": "^1.6.32",
"gatsby-plugin-react-helmet": "^1.0.8",
"gatsby-plugin-react-next": "^1.0.6"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"main": "n/a",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"src/**/*.js\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "^1.9.2"
}
}
Actual result
Active Links should be styled bold - also on initial page load and not only after navigation did occur. Testlink: http://gatsbynext-router.surge.sh/my-gatsby-site/page-2
Expected behavior
Same example as above, but without gatsby-plugin-react-next
.
Testlink: http://gatsbynext-router-react15.surge.sh/my-gatsby-site/page-2
Steps to reproduce
-
Setup new vanilla gatdbyJS project
-
Add
gatsby-plugin-react-next
plugin -
Make use of
activeStyle
oractiveClassName
at the<Link>
components, that come with the gatsbyJS boilerplate. Egpage-2.js
:
<Link activeStyle={{ fontWeight: 'bold' }} to="/">
Go back to the homepage
</Link>
<br />
<Link activeStyle={{ fontWeight: 'bold' }} to="/page-2/">
Go to page 2
</Link>
-
Add a
pathPrefix
(seegatsby-config.js
above) and build a production version of the project usinggatsby build --prefix-paths
-
See result using eg.
gatsby serve
and test it by initialting page refreshes and navigation
mv public my-gatsby-site
mkdir public
mv my-gatsby-site public
gatsby serve
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top GitHub Comments
Link
’s behaviour has changed whenreach/router
has replacedreact-router
. @KyleAMathews mentioned here that newLink
won’t get that capability. So I wrote my customLink
wrapper, here it is in case someone else needs:Also encountering this (active links don’t get styles on page refresh until client route changes happen). @ooloth’s problem is something other than the original issue I believe.