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

Similar signature as vue-router #6

Open
msaelices opened this issue Feb 10, 2019 · 1 comment
Open

Similar signature as vue-router #6

msaelices opened this issue Feb 10, 2019 · 1 comment

Comments

@msaelices
Copy link

msaelices commented Feb 10, 2019

For the sake of the code sharing experience, it would be great that:

  • The internal object created in the Vue instance was $router
  • The $navigator.navigate(to, options) method would be $router.push(to, options)
  • $router.replace(to) would be implemented as the current $navigator.navigate(to, {clearhistory: true})
  • $router.go(-1) would be implemented as the current $navigator.back()

If this was refactored, the basic navigation could be shared for mobile and web. And this would be an excellent starting point for a better vue-router integration with other non-web implementations.

@CoreyKaylor
Copy link

I was able to lean on the existing $router variable by doing these hackish changes on startup as a temporary workaround. It's still better than having conditional code for web and native everywhere that needs to route somewhere... I'm sure there will be more things to add and address, but simplifies downstream code quite a bit from what I can tell.

Navigator.push = route => {
    Vue.prototype.$navigator.navigate(route);
};
Navigator.init = () => {};
Navigator.history = {
  current: "/"
};

Then when creating the Vue instance you can change to...

new Vue({
  router: Navigator,
  store,
  render: h => h("frame", [h(App)])
}).$start();

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