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
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