i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Generating localised routes for page aliases

Open EvilaMany opened this issue 2 years ago • 6 comments

Describe the feature

My app has only 1 page, that should have many possible urls to be resolved by (for SEO purposes). The page should only change some translations depending on url it was resolved by. I created single pages/index.vue and set definePageMeta({ alias... }). But nuxti18n generate only localised route for main page url, not for any of aliases.

For example I have two aliases: /dogs-info /cats-info

In pages/index.vue I set alias as follows definePageMeta({ alias: ["/dogs-info", "/cats-info"] })

I expect that I will have routes: / /pl /es /dogs-info (default locale) /cats-info (default locale) /pl/dogs-info /pl/cats-info /es/cats-info /es/dogs-info

But I have only: / /pl /es

Additional information

  • [x] Would you be willing to help implement this feature?
  • [ ] Could this feature be implemented as a module?

Final checks

EvilaMany avatar Dec 07 '23 13:12 EvilaMany

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 Reproduction starter (v8 and higher) 👉 Reproduction starter (edge)

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

github-actions[bot] avatar Dec 07 '23 14:12 github-actions[bot]

Reproduction: https://stackblitz.com/edit/github-g8bh9l

EvilaMany avatar Dec 07 '23 14:12 EvilaMany

Maybe I misunderstand, but wouldn't the /cats page have different content from the /dogs page? Which would have its own translations?

BobbieGoede avatar Dec 07 '23 14:12 BobbieGoede

Not really. My app should have multiple pages with the almost same layout and view, but different urls and translations based on url it resolved by. This differences will lay deeply inside page, in few components. All the other content are the same. Also there are should be possibility to change url to another alias, without rerendering the page itself. I need to rerender only content in components with url based content, but all the other page with inputs etc should save state. So it make sense to make computed-s based on current route.pathname (alias), instead of creating N separate pages

EvilaMany avatar Dec 07 '23 14:12 EvilaMany

Mostly it's SEO tricks, so I recommend not to find logic here (=

EvilaMany avatar Dec 07 '23 14:12 EvilaMany

You can use hooks like this:

export default defineNuxtConfig({
	hooks: {
		'pages:extend'(pages) {
			pages.push({
				name: `dogs-info`,
				path: `/dogs-info`,
				file: resolve(__dirname, 'pages/index.vue')
			});
			pages.push({
				name: `cats-info`,
				path: `/cats-info`,
				file: resolve(__dirname, 'pages/index.vue')
			});
		}
	}
})

qiuyu303 avatar Mar 15 '24 15:03 qiuyu303