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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Empty route.params object on navigation #121

Open
quezadaesteban opened this issue Oct 26, 2022 · 5 comments
Open

fix: Empty route.params object on navigation #121

quezadaesteban opened this issue Oct 26, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@quezadaesteban
Copy link

πŸ› The bug

When navigating to a new page, the route.params object from useRoute is empty.

πŸ› οΈ To reproduce

https://stackblitz.com/edit/github-hz29vt?file=pages/tabs/tab1.vue

🌈 Expected behaviour

It should be an object with the current route parameters, query, etc.

ℹ️ Additional context

  • It works properly on 0.6.1.
  • After navigating, reloading the page makes the route.params object show the correct content.
@quezadaesteban quezadaesteban added the bug Something isn't working label Oct 26, 2022
@quezadaesteban
Copy link
Author

quezadaesteban commented Jan 30, 2023

This is still broken on @nuxtjs/ionic v.0.8.1. w. Nuxt 3.1.0.

@MikeyBeLike
Copy link

MikeyBeLike commented Feb 20, 2023

I had this issue, how I fixed it was by importing it from vue router.

import { useRoute } from 'vue-router';

and using this one rather than the auto imported one

Tested on "@nuxtjs/ionic": "^0.8.0", && "nuxt": "3.0.0",
Still an issue that needs to be observed

@chrisspiegl
Copy link

I ran into the same. The workaround provided by @MikeyBeLike seems to work.

I tried looking if there is a way to globally (in the nuxt.config.ts) import the vue-router but I have not found a way yet.

Maybe there is one… please let me/us know if you know a way.

Thanks

@quezadaesteban
Copy link
Author

The solution given by @MikeyBeLike worked! In my case, I have something like this in the composable (so it is global). I only had to add the import in the composable, and everything worked again as expected.

import { useRoute } from 'vue-router'

// ...

export const useNavigation = () => {
  const router = useIonRouter();
  const route = useRoute();

  return {
    route,

    push: (name: RouteName, options?: RouteOptions) => {
      router.push({ name, params: options?.params });
    },

    replace: (name: RouteName) => router.replace({ name }),
  };
};

So in my components, I can do:

const navigation  = useNavigation()
// and then
navigation.route // same as const route = useRoute()
navigation.push('home') // route name is hinted by RouteName type.
navigation.replace('home') // same as `push`

Regardless, it is still an issue that needs to be addressed.

@chrisspiegl
Copy link

That's "a way" but does not solve the issue of having to use something non standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants