lib icon indicating copy to clipboard operation
lib copied to clipboard

SEO friendly default locale routes

Open snorreks opened this issue 2 years ago • 11 comments

Wondering if this project will be able to autogenerate routes like @nuxtjs/i18n ? And also support that the default locale will not have a prefix. The current locale-router example does not support removing prefix for the default locale.

If it is not possible autogenerate the routes, how could I make the default locale not have prefix with the current solution? Maybe duplicate all pages in [lang] and move it directly in pages?

snorreks avatar May 24 '22 08:05 snorreks

I think it might work using hooks.js… maybe replacing this redirect and serving the appropriate language mutation instead. But not tested yet..

jarda-svoboda avatar May 24 '22 09:05 jarda-svoboda

As pointed out in #77 this should be the default approach for the locale-router example because of SEO…

jarda-svoboda avatar May 26 '22 09:05 jarda-svoboda

Ah yes without this locale-router is not feasible from a SEO perspective.

Sorry for the duplicate.

Swepool avatar May 26 '22 10:05 Swepool

Also seems to switch multiple times

User hits "/" and gets redirected to "/en/" then redirected again to "/en"

image

Swepool avatar May 26 '22 23:05 Swepool

Hmmm been playing around with the hook, but can't get it to work properly.. would be such a nice thing to have 😅

Swepool avatar May 26 '22 23:05 Swepool

Agreed, I also tried with no success of far, but I think I’m close..)

jarda-svoboda avatar May 27 '22 07:05 jarda-svoboda

Ok, have it... https://github.com/sveltekit-i18n/lib/pull/79/files

I'm not sure if it should also redirect the /defaultLocale/page back to /page or not...? Also nav links within the site now points to /$locale/page which should be probably fixed for the default locale as well...

jarda-svoboda avatar May 28 '22 14:05 jarda-svoboda

Works well, I think for SEO purposes the / page and /defaultLocale/page will act as duplicates and crawlers will be able to find the links on site, so would probably be best to have only / as default?

Swepool avatar May 28 '22 17:05 Swepool

Ok worked locally but can't access when published, doesn't get out of pending state.

https://629259c0302e9824c3b26832--testlocale.netlify.app/

Swepool avatar May 28 '22 17:05 Swepool

If u add /en it goes through. But dynamic routes, in this case [post] is confused, I believe 🤔 - /sv/blog/post becomes /blog/post

Swepool avatar May 28 '22 17:05 Swepool

ok, netlify done https://locale-router.netlify.app unfortunately the workaround is a bit hacky (or non-elegant) – i'd rather use something like:

return resolve(MODIFIED_EVENT)

but still can't figure out how to modify the original event to fetch /locale/page route instead of the original (locale unprefixed) one...

my current solution is here: https://github.com/sveltekit-i18n/lib/pull/79/commits/d5c09d83d0d2737e3c9c5bd233a9c48552f1f20f

jarda-svoboda avatar May 28 '22 23:05 jarda-svoboda