It took me way too long to figure this one out, but here it is:
// Doesn't change when route changesconst route = useRoute();// Changes when route changesconst path = useRoute().path;
If we need the full route object in a reactive way, we can do this:
// Doesn't change when route changesconst route = useRoute();// Changes when route changesconst route = useRouter().currentRoute.value;
With the Options API you can use $route
and $router
to get objects that update whenever the route changes.
Since Nuxt uses Vue Router internally, this works equally well in Nuxt and vanilla Vue apps.
Here's a demo to see this for yourself: Demo