nativescript-vue / nativescript-vue-navigator

A simple router for NativeScript-Vue, built on top of $navigateTo to simplify routing from within components
MIT License
98 stars 10 forks source link

Similar signature as vue-router #6

Open msaelices opened 5 years ago

msaelices commented 5 years ago

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

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 commented 5 years ago

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();