How to redirects unmatched Links to a existing Link
Go to a Link which isn't exist.
Redirects to 404 component.
Directs to a page where it shows the Links (pages) I have in my project with 404 page.
npm list gatsby): [email protected]gatsby --version): 1.1.50gatsby-config.js:
module.exports = {
siteMetadata: {
title: `Thidasa Pankaja`,
},
plugins: ['gatsby-plugin-react-helmet',
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "xxxxxx",
// Puts tracking script in the head instead of the body
head: false,
// Setting this parameter is optional
anonymize: true,
// Setting this parameter is also optional
respectDNT: true,
},
},
],
}
package.json:
{
"name": "gatsby-starter-default",
"description": "Gatsby default starter",
"version": "1.0.0",
"author": "Kyle Mathews <[email protected]>",
"dependencies": {
"gatsby": "^1.9.247",
"gatsby-link": "^1.6.40",
"gatsby-plugin-google-analytics": "^1.0.31",
"gatsby-plugin-react-helmet": "^2.0.10",
"react-helmet": "^5.2.0",
"styled-components": "^3.2.6"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write 'src/**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "^1.12.0"
}
In production build, it directs to 404 page.
Hey guys!
I'm currently hosting a Gatsby build on a firebase instance.
Everything works like a charm 👌 except the 404.
What happens is that for any "wrong" urls such as /foo-bar, firebase renders the 404.html page that Gatsby has created. All good so far, but then the JS kicks in, and the React routing doesn't match the current url (it doesn't find any page to render), therefore removes from the DOM the pre-rendered elements.
According to the previous comment, that should be fixed in production but I still have the issue.
Any hint on how to fix this? Worst case scenario I could set up some redirects rules within the Firebase configuration, but I'd love to know if Gatsby is able to handle situations like this.
Thank you very much!
Most helpful comment
Hey guys!
I'm currently hosting a Gatsby build on a firebase instance.
Everything works like a charm 👌 except the 404.
What happens is that for any "wrong" urls such as
/foo-bar, firebase renders the404.htmlpage that Gatsby has created. All good so far, but then the JS kicks in, and the React routing doesn't match the current url (it doesn't find any page to render), therefore removes from the DOM the pre-rendered elements.According to the previous comment, that should be fixed in production but I still have the issue.
Any hint on how to fix this? Worst case scenario I could set up some redirects rules within the Firebase configuration, but I'd love to know if Gatsby is able to handle situations like this.
Thank you very much!