iceberg-gatsby-multilang
iceberg-gatsby-multilang copied to clipboard
Route change path bug
When switching language, I often end up with erroneous paths, yielding a blank or 404 page. In both Chrome and Firefox.
http://localhost:3000/pt//blog ->Â When switching from EN version
http://localhost:3000/pt/contato/pt/contato -> when re-clicking on contao in the menu
http://localhost:3000/pt/pt/sobre ->Â when clicking "sobre" in the menu from http://localhost:3000/pt
http://blog/adding-menu-items (set as absolute url - no protocol). -> when switching from the PT version.
I did some test adding new files, but git stash
all changes, ran gatsby clean
, used the default port, but the issue is still present. It's such a big problem, that I've assume it's project specific, but I've reverted to the initial repo. Is there some hidden cache that is gitignored
and not cleared by gatsby clean
?
This is happening both in the develop
and build
versions.
Perhaps it's only affecting localhost? Is this an issue you ran into previously?
This is happening to me too. Maybe it's something that has only recently surfaced. It'd be great to hear if anyone has fixed it or hasn't had this problem.
I've fixed it, but I daresay it's a hacked solution.
I did 2 things.
- In
src/components/LocalizedLink.js
, I applied a starting slash to the Link path only when not using the default lang. This stops the multiple layers of e.g./pt/blog/pt/contato
:
const path = locales[locale].default
? to
: `/${locales[locale].path}${isIndex ? `` : `${to}`}`;
return <Link {...props} to={path} />;
- In
src/components/Languages/index.js
, I stopped the double slash bug when switching from EN version:
const singleSlashSlug = associatedUrls[lang].replace(/\/\//g,'/');
return lang === "en" ?
navigate(singleSlashSlug) :
navigate(`/${lang}${singleSlashSlug}`);
I'm not 100% sure this solution is worth a PR as there could be a different reason for why the path started with this odd behaviour. It'd be useful to know if this is a recent issue. And to know if the code currently published on netlify https://iceberg-gatsby-multilang.netlify.app/ is that from master.
Let me know what you think @diogorodrigues @iplanwebsites.
I started deleting things around that I think I won't use and this bug happened.
I found out that removing the netlify plugin causes this bug, don't ask me why. The reason I'm deleting it is because I will deploy somewhere else and I won't use netlify cms.