-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
Hi - thanks for a great web framework!
In general, we try to use Vuex state and actions to drive our views according to the flux pattern. This means that we have a pretty standard flow of information:
Async input events => Actions => Mutations => View updates
* user input
* server data
* timers
Routing events are asynchronous input events. Clicking a link or manually modifying or entering a URL are user-driven actions that can happen at any time, similar to clicking a button.
However, the <router-view> component behaves differently: it bypasses Vuex by associating user input (routing events) directly with view updates (showing a component). This gives rise to a different information flow:
Routing event => View update
v v
beforeRouteEnter watch $route => View update
This creates some complexity as views need to handle events and watch the $route for changes, e.g.:
- https://router.vuejs.org/guide/advanced/data-fetching.html
- [Feature] A reload method like location.reload() #296 (comment) (note - I've also run into this issue and agree a
reloadmethod could be helpful...)
It also makes vuex-router-sync somewhat strange, because the route info gets stored in Vuex independently of the Vue components being updated, whereas typically they're updated because of Vuex.
Instead of mapping routes to components, we've tried mapping routes to actions. In practice, this means having an unused <router-view> and doing something like:
Routing event => no-op
v
beforeRouteEnter => Action => Mutation(s) => View update(s)
This allows us to drive all loading, page-switching, and rendering state logic from the Vuex store rather than inside of components. It also makes it really easy to embed a lot of state in the URL, and then make updates by calling router.push or router.replace rather than directly triggering an action (e.g. to change the sort-order or filter options of a table).
It would be cool is if there was first-class support for associating Vuex actions with routes:
Routing event => Action => Mutation(s) => View update(s)
In this setup many 'features' become redundant or unnecessary: e.g. <router-view>, route transitions, the $route attribute, navigation guards, and vuex-router-sync
Just speculation: perhaps there's also opportunity to associate nested routes with the new Vuex 2.0 nested modules...
thanks for your consideration!