ionic
ionic copied to clipboard
help: Access additional Route Information
📚 What are you trying to do?
I need the information from the route to find the active link; since we are not using NuxtLink. I needed to hack into the configuration to get the information and was wondering if there is an easier way?
$nuxt.config.globalProperties.$router?.currentRoute;
🔍 What have you tried?
$nuxt.config.globalProperties.$router?.currentRoute;
This works, but wondering if there is a cleaner way, when I call useIonicRouter
it doesn't have the additional route information
ℹ️ Additional context
See example code here https://stackblitz.com/edit/nuxt-starter-rqvhxt?file=components%2FMainMenu.vue
I'm also interested in a solution, as with nuxt rc5 window.$nuxt was removed and this workaround doesn't work anymore. Did you find a different solution @aaronksaunders?
Edit: I found a different workaround, but I don't know if it is a proper solution to use vue-router:
import { useRouter } from 'vue-router'
const { currentRoute } = useRouter()
const id = currentRoute.value.params.id
$nuxt.config.globalProperties.$router?.currentRoute;
will get you access to the route
You could also just directly get current route (worked for me)
import { useRoute } from 'vue-router'
const route = useRoute()
One thing to point out would be that even tho ionic has it's own implementation of the router, it doesn't include any info about current route
import { useIonRouter } from '@ionic/vue'
const router = useIonRouter()
router.currentRoute // Doesn't exist...
It might be an oversight, but I guess this implementation should only be used for pushing or replacing new routes
@Lexpeartha that is what I use the workaround mentioned here... to get all of the route information