How to translate slugs with Nuxt.js and Storyblok
Storyblok is the first headless CMS that works for developers & marketers alike.
In this article I explain how to use a translated slug with nuxt. I also show you a really simple real life example with Storyblok .
Use cases
You can use Storyblok for basically everything! Use it for e-commerce, a personal website, blog, etc. As you may know, these days SEO is really important. Having a translated URL for your website will boost your SEO performance. Check out the google documentation , it encourages you to do that.
Let's create the project
If you already have a project with
nuxt
and
nuxt-i18n
skip to the next point. Or check out the
code
directly. (
Live demo
)
bash
Make sure to select axios . From here you need to install nuxt-i18n .
bash
You need to create a file store/index.js to activate the store in your NuxtJS project and make Nuxt i18n work.
Static page with translated slugs
For the static pages, you can check the docs . You can configure it in the module configuration inside your nuxt.config.js or directly in components. Here is an example of how to use it in a component:
pages/contact.vue
Important : If the filename is different from the default lang use this example to navigate to it.
Let's use dynamic URLs with Storyblok.
For dynamic URLs I could have used Nuxt content. But as I have worked on a lot of eCommerce websites, I prefer doing it with Storyblok .
First, let's see how to use
dynamic routes parameters
with
nuxt-i18n
. You will need to use
'i18n/setRouteParams'
actions from your Vuex store. Your file will look like
pages/_articleId.vue .
pages/_articleId.vue