useRoute inside plugin
Is this suggestion correct?
plugin is something like this:
if true, show sources
Don't call useRoute inside a Nuxt plugin setup—it's only available in component
contexts. Instead, read the route name from the router instance on the Nuxt app.
This ensures the plugin works both on server and client side.Don't call useRoute inside a Nuxt plugin setup—it's only available in component
contexts. Instead, read the route name from the router instance on the Nuxt app.
This ensures the plugin works both on server and client side.plugin is something like this:
export default defineNuxtPlugin({
name: 'plugin',
parallel: true,
setup: async () => {
const route = useRoute();
if (route.name === 'my-route') {
doSomething()
}
},
});export default defineNuxtPlugin({
name: 'plugin',
parallel: true,
setup: async () => {
const route = useRoute();
if (route.name === 'my-route') {
doSomething()
}
},
});if true, show sources
