Skip to content

Commit

Permalink
feat: expose START_LOCATION
Browse files Browse the repository at this point in the history
Close #2718
  • Loading branch information
posva committed Jan 5, 2021
1 parent d2cb951 commit 53b68dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@ Since it's just a component, it works with `<transition>` and `<keep-alive>`. Wh
The current route represented as a [Route Object](#the-route-object).
### router.START_LOCATION
- type: `Route`
Initial route location represented as a [Route Object](#the-route-object) where the router starts at. Can be used in navigation guards to differentiate the initial navigation.
```js
import Router from 'vue-router'

const router = new Router({
// ...
})

router.beforeEach((to, from) => {
if (from === START_LOCATION) {
// initial navigation
}
})
```
## Router Instance Methods
### router.beforeEach
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ VueRouter.install = install
VueRouter.version = '__VERSION__'
VueRouter.isNavigationFailure = isNavigationFailure
VueRouter.NavigationFailureType = NavigationFailureType
VueRouter.START_LOCATION = START

if (inBrowser && window.Vue) {
window.Vue.use(VueRouter)
Expand Down
2 changes: 2 additions & 0 deletions types/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export declare class VueRouter {
static NavigationFailureType: {
[k in keyof typeof NavigationFailureType]: NavigationFailureType
}

static START_LOCATION: Route
}

export enum NavigationFailureType {
Expand Down

0 comments on commit 53b68dd

Please sign in to comment.