maison margiela
maison margiela
NNuxt
Created by maison margiela on 8/12/2024 in #❓・help
nuxt 3 global middleware for redirecting
I am trying to implement a middleware which will run always in case if someone is trying to hit a /app route. Middleware should make auto redirect to /app/chat. Also i have a localization made by @nuxtjs/i18n which save locale code to cookie and then use it. I implemented like that import { useRouter } from "vue-router"; export default defineNuxtRouteMiddleware((to, from) => { const router = useRouter(); const localePath = useLocalePath(); if (to.path === "/app") { console.log("Redirecting to /app/chat"); return router.push(localePath("/app/chat")); } }); Whole path will look like localhost:3000/cs/app -> localhost:3000/cs/app/chat But looks like my middleware is not working, because i dont even see logs in my console
28 replies
NNuxt
Created by maison margiela on 8/12/2024 in #❓・help
Using @nuxtjs/i18n version 8.3.3, implementing auto redirect on success.
Hi, i have a struggle using "@nuxtjs/i18n": "^8.3.3" in my nuxt project. On submit form on success i want to implement auto redirtect and for that i am using await router.push(localePath("/registration/complete")); to navigate to lokalization path based on a cookie I also imported: import { useI18n } from "vue-i18n"; import { useRouter } from "vue-router"; const router = useRouter(); const { locale, t, localePath } = useI18n(); But i am getting error: localePath is not a function. My nuxt config: i18n: { lazy: true, langDir: "locales", strategy: "prefix_except_default", locales: [ { code: "en", iso: "en", name: "English", file: "en.json", }, { code: "fr", iso: "fr", name: "Français", file: "fr.json", }, { code: "de", iso: "de", name: "Deutsch", file: "de.json", }, { code: "cs", iso: "cs", name: "Čeština", file: "cs.json", }, { code: "es", iso: "es", name: "Español", file: "es.json", }, { code: "pl", iso: "pl", name: "Polski", file: "pl.json", }, ], defaultLocale: "en", detectBrowserLanguage: { useCookie: true, cookieKey: "locale", alwaysRedirect: true, fallbackLocale: "en", }, }, Am i doing something wrong?
6 replies