ionic icon indicating copy to clipboard operation
ionic copied to clipboard

help: Access additional Route Information

Open aaronksaunders opened this issue 2 years ago • 4 comments

📚 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

aaronksaunders avatar Jun 24 '22 15:06 aaronksaunders

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

lstegger avatar Jul 19 '22 15:07 lstegger

$nuxt.config.globalProperties.$router?.currentRoute;

will get you access to the route

aaronksaunders avatar Jul 19 '22 17:07 aaronksaunders

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 avatar Jul 26 '22 09:07 Lexpeartha

@Lexpeartha that is what I use the workaround mentioned here... to get all of the route information

aaronksaunders avatar Jul 27 '22 15:07 aaronksaunders