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

Access all routes from the $navigator object #44

Open
mreall opened this issue Jun 24, 2020 · 2 comments
Open

Access all routes from the $navigator object #44

mreall opened this issue Jun 24, 2020 · 2 comments

Comments

@mreall
Copy link

mreall commented Jun 24, 2020

It would really be helpful to have access to all the routes from the $navigator object. Right now we can only access the current route.

This would be helpful, for example, if I want to define a default transition for each route in the meta object. Then when I call this.$navigator.navigate I can pass in the default transition for the route.

routes.js example:

export default {
   routes: {
      '/page1': {
         component: Page1,
         meta: {
            transition: 'fade',
         }
      },
      '/page2': {
         component: Page2,
         meta: {
            transition: 'slideBottom',
         }
      },
}

Then in a component used for routing:

  methods: {
    /***
     * Called when a user taps a navigation button.
     * @param string to Page ID from the routes.js file.
     ***/
    route(to) {
      let transition = 'fade';
      const route = this.$navigator.getRoute(to);    // getRoute is a possible new method to access the routes.
      if (route && 'transition' in route.meta) {
        transition = route.meta.transition;
      }
      this.$navigator.navigate(to, { frame: "mainContent", transition });
    },
  }
@gravataLonga
Copy link

Why not import router.js where you want to access.. ? Don’t know..

@mreall
Copy link
Author

mreall commented Jun 24, 2020

That's certainly an option. As a workaround I also assigned it to Vue, i.e. Vue.prototype.$routes = routes. But a logical place for it is with the Navigator.

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

No branches or pull requests

2 participants