A convenient replacement for component when using nuxt-i18n

Related tags

Nuxt nuxt-i18n-link
Overview

nuxt-i18n-link

A convenient replacement for <nuxt-link> component when using nuxt-i18n. It is simply a replacement for this exact code:

<nuxt-link :to="localePath("/page")">
	Link
</nuxt-link>

into

<nuxt-i18n-link to="/page">
	Link
</nuxt-i18n-link>

This prevents the mistake of omitting localePath() that would often fall under the radar. More details

Usage

Install with

npm i nuxt-i18n-link

Note: Add --save if npm < 5.0.0

Then nuxt.config.js

{
	modules: [
		'nuxt-i18n-link'
	]
}

Finally, use like

<nuxt-i18n-link to="/page" lang="en">
	Link
</nuxt-i18n-link>

// or

<nuxt-i18n-link to="{ path: '/page', hash: '#conclusion'}" lang="en">
	Link
</nuxt-i18n-link>

For more details, see router-link.

Props

Name Type Default Required Description
to string | object - [x] Destination Route (see router-link)
lang string undefined [ ] Two-letter ISO language code

Motivation

The use of localePath() in <nuxt-link> is necessary for Nuxt.js projects that use nuxt-i18n.

To demonstrate, say a project has two routes:

  1. Home page /
  2. About page /about

Using nuxt-i18n, these routes will become

English French
/ /en/ /fr/
/about /en/about /fr/about

However, <nuxt-link to="/about"> will not route to /en/about nor /fr/about but to /about which does not exist anymore. The documented solution to this is to use localePath() as <nuxt-link :to="localePath('/about')">, which will route to /en/about or /fr/about according to the current language.

The documented solution is easily forgotten, and <nuxt-link to="about"> will not produce any errors when a default language is defined. Moreover, the error is not immediately obvious unless the non-default languages are being tested.

Hence, <nuxt-i18n-link> was made.

MIT License

You might also like...
An experiment of using Nuxt 3 Beta to get data from Star War API
An experiment of using Nuxt 3 Beta to get data from Star War API

An experiment of using Nuxt 3 Beta to get data from Star War API This project is

Nefa - Free landing page template built using nuxt and tailwindcss
Nefa - Free landing page template built using nuxt and tailwindcss

NEFA Landing Page Free landing page template built using Nuxt 2 and Tailwindcss

nuxt-fullpage is a nuxt module for creating fullscreen page scroll fast and simple.

Nuxt fullpage Nuxt module for creating fullscreen page scroll fast and simple. Demo online Table of contents Installation Usage Options Contributing I

Nuxt basic - Simple Nuxt.js project

nuxt_basic Build Setup # install dependencies $ npm install # serve with hot reload at localhost:3000 $ npm run dev # build for production and launc

Fcl-nuxt-starter - FCL plugin + full stack Nuxt application starter template
Fcl-nuxt-starter - FCL plugin + full stack Nuxt application starter template

How to use the Flow Client Library (FCL) with Nuxt Access the FCL instance from

Frisque-nuxt-storyblok - A basic framework for integrating StoryBlok with Nuxt

🌺 Frisque StoryBlok Welcome to the Frisque StoryBlok starter kit! This is curre

Netlify ❤️ Nuxt.js: a simple template to give you the code you need to use Netlify features with Nuxt.
Netlify ❤️ Nuxt.js: a simple template to give you the code you need to use Netlify features with Nuxt.

Nuxt Toolbox Template This is a NuxtJS v2 project. It is a reference on how to integrate commonly used features within Netlify for Nuxt.js. Build Setu

A lightweight Nuxt template to build a Markdown driven website. Powered by Nuxt Content, TailwindCSS and Iconify.
A lightweight Nuxt template to build a Markdown driven website. Powered by Nuxt Content, TailwindCSS and Iconify.

A lightweight Nuxt template to build a Markdown driven website. Powered by Nuxt Content, TailwindCSS and Iconify.

WordPress module for Nuxt.js with full support for SSR and Nuxt.js PWA module.

WordPress module for Nuxt.js with full support for SSR and Nuxt.js PWA module.

Releases(v1.0.3)
Owner
iBlueDust
web dev hobbyist
iBlueDust
The Weather project displays information using the API, written using NUXT.js

The Weather project displays information using the API. Among the important points of the seven-day information are three different cities. This project modeled on a shot in dribbble written using NUXT.js

Amirhossein Zebardast 12 Oct 28, 2022
This is nuxt invoice app using nuxt.js and firebase

Nuxt Invoice App Build Setup # install dependencies $ npm install # serve with hot reload at localhost:3000 $ npm run dev # build for production and

Moein Salari 8 Dec 20, 2022
English-quiz-nuxt - An english quiz using nuxt

english-quiz-nuxt Live demo here Build Setup # install dependencies $ yarn insta

Leonid Gainar 2 Feb 17, 2022
A simple nuxt renderless component wrapper around nuxt fetch capabilities

Nuxt Fetch Component A simple nuxt renderless component wrapper around nuxt fetc

Mathieu Marteau 6 Apr 12, 2022
Check trending anime based on anitrendz.net site. Built using nuxt

animetrend Demo: here Build Setup # install dependencies $ npm install # serve with hot reload at localhost:3000 $ npm run dev # build for productio

Ricko Veriyanto 2 Aug 10, 2022
Discuss with Atinux Demo of using Nuxt 3 with GitHub authentication and creating issues with real-time updates.

Discuss with Atinux Demo of using Nuxt 3 with GitHub authentication and creating issues with real-time updates. See it live on https://discuss.atinux.

Sébastien Chopin 104 Dec 13, 2022
A beautiful blog using Nuxt.js

Blog Epic blog I made: https://explosion-scratch.github.io/blog Uses tailwind, Nuxt and SCSS. How stuff is made: Front page: Uses the CSS drop-shadow

--Explosion-- 14 Sep 29, 2022
Strapi & Nuxt.js e-commerce app using Snipcart

Strapi & Nuxt.js e-commerce app using Snipcart Follow this step-by-step tutorial to learn how to use Nuxt.js & Snipcart to build an e-commerce PWA in

Snipcart 14 Dec 9, 2022
Github'st Development Archive Application using vue and nuxt

cat-hub Github'st Development Archive Application using vue and nuxt. Link You can check here. Tech and libraries vue vuex vuetify sass nuxt nuxt/cont

Lee Sang Min 5 Nov 22, 2022
A nuxt application using movie data api

nuxt-movie-app Build Setup # install dependencies $ npm install # serve with hot reload at localhost:3000 $ npm run dev # build for production and l

Marko Goronjic 0 Dec 11, 2021