Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

help: Access additional Route Information #16

Closed
aaronksaunders opened this issue Jun 24, 2022 · 4 comments 路 Fixed by #59
Closed

help: Access additional Route Information #16

aaronksaunders opened this issue Jun 24, 2022 · 4 comments 路 Fixed by #59
Assignees

Comments

@aaronksaunders
Copy link
Contributor

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

@lstegger
Copy link

lstegger commented Jul 19, 2022

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

@aaronksaunders
Copy link
Contributor Author

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

will get you access to the route

@Lexpeartha
Copy link
Collaborator

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

@aaronksaunders
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants