-
Notifications
You must be signed in to change notification settings - Fork 10
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
routes with and without trailing forward slash causes route "misses" #331
Comments
Well, now adding the forward slash removes the
Note: our site doesn't add the cc: @hutchgrant |
For our site, the solution on netlify is:
Which eliminates forcing the trailing slash. The problem is that we're caching routes without the trailing / and therefore when we visit URLs with the trailing / our cache does not contain a matching route which gives us these errors when it hydrates the graphql query. Quick solution is to stop forcing trailing slash from netlify to begin with; its unnecessary. We can probably close this issue because this is a special case and we cannot accommodate everyone's url rewrite rules. For netlify, maybe we can document this fix somewhere, maybe in build/deploy ? Index pages will always have a trailing / and every other page will not have a trailing slash. This is assuming that the host doesn't rewrite the links (pretty urls via netlify). This is clear within the graph.js lifecycle: // get md file's name without the file extension
let fileRoute = subDir.substring(seperatorIndex, subDir.length - 3);
// determine if this is an index file, if so set route to '/'
let route = fileRoute === '/index' ? '/' : fileRoute; We do this so that we don't have links such as |
We could also eliminate trailing slash from index page routes as well.
The issue with that is: if you have a file We would have a duplicate route pointing to different pages. |
Good call @hutchgrant on Netlify settings . Applied this setting for now, seems to have fixed the issue. 💯 Let me add this issue to our Tuesday agenda to make sure there's nothing else we should be doing and / or documenting. |
So the question is: What should our default link format be, with or without a forward slash; |
From this PR, maybe anywhere we have to do some sort of matching, we should use a RegExp? const route = window.location.pathname;
/* get some pages from GraphQL */
const currentPage = response[1].data.graph.filter((page) => {
return new RegExp(`^${path}$`).test(list.item.link);
})[0]; Then we could only have |
This comment has been minimized.
This comment has been minimized.
I've normalized all routes as ending with |
Type of Change
Summary
As evidenced in PR #308, it looks like if there is or isn't a forward slash at the end of a route. e.g.
http://domain.com/about
vs.
http://domain.com/about/
Can lead to issues with matching against active routes in GraphQL / coming out of the Greenwood graph and even cause errors in the console, although I think Netlify will add / forward to the
/
so then it "catches".Details
I think anywhere where we are matching against an active route or using
window.location.hostname
or similar to find out the current page, we will need to evaluate how it is being implemented and try and build a fairly robust / non fragile solution.Also see #310 for reference.
The text was updated successfully, but these errors were encountered: