Skip to content

Commit 53b68dd

Browse files
committed
feat: expose START_LOCATION
Close #2718
1 parent d2cb951 commit 53b68dd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

docs/api/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,26 @@ Since it's just a component, it works with `<transition>` and `<keep-alive>`. Wh
319319

320320
The current route represented as a [Route Object](#the-route-object).
321321

322+
### router.START_LOCATION
323+
324+
- type: `Route`
325+
326+
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.
327+
328+
```js
329+
import Router from 'vue-router'
330+
331+
const router = new Router({
332+
// ...
333+
})
334+
335+
router.beforeEach((to, from) => {
336+
if (from === START_LOCATION) {
337+
// initial navigation
338+
}
339+
})
340+
```
341+
322342
## Router Instance Methods
323343

324344
### router.beforeEach

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ VueRouter.install = install
280280
VueRouter.version = '__VERSION__'
281281
VueRouter.isNavigationFailure = isNavigationFailure
282282
VueRouter.NavigationFailureType = NavigationFailureType
283+
VueRouter.START_LOCATION = START
283284

284285
if (inBrowser && window.Vue) {
285286
window.Vue.use(VueRouter)

types/router.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export declare class VueRouter {
7575
static NavigationFailureType: {
7676
[k in keyof typeof NavigationFailureType]: NavigationFailureType
7777
}
78+
79+
static START_LOCATION: Route
7880
}
7981

8082
export enum NavigationFailureType {

0 commit comments

Comments
 (0)