Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add route.from property to RouterView::route (#2872)
Adds the ability to inspect the `route` of the previous page, i.e. the history using `RouteView::route.from`. This is useful for if we need to take the user to a certain page depending on where they came from. --- We could use native `location.history` to do things like this, but it doesn't give you Vue route information. The downside is here, we only store the single previous page, i.e. where you came from not the full history. This feels like Vue more seeing as Vue only works with the idea of `from`. I doubt we'll need to store a full history of routes for anything, so this is fine for the moment. If we ever need to store a full history we can do that under `route.history`, and keep `route.from` as a shortcut to `route.history[0]`. --- I also changed some naming inside RouteView here. RouteViews are nested so all of them haveParents apart from the top one (i.e. the root RouteView), and only the root RouteView doesn't have a root 🤯 . The implementation just tracks all route changes in the root RouteView (the one that is always on the page) using Vue's `route.beforeEach` callback, and all child routes then read from the property we keep up-to-date using this callback (`route.from`). --- Signed-off-by: John Cowen <[email protected]>
- Loading branch information