Skip to content

Commit 2cd8d86

Browse files
committed
feat(warn): more specific warnings
1 parent 8dad632 commit 2cd8d86

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/navigationGuards.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function registerGuard(
5252
*/
5353
export function onBeforeRouteLeave(leaveGuard: NavigationGuard) {
5454
if (__DEV__ && !getCurrentInstance()) {
55-
warn('onBeforeRouteLeave must be called at the top of a setup function')
55+
warn(
56+
'getCurrentInstance() returned null. onBeforeRouteLeave() must be called at the top of a setup function'
57+
)
5658
return
5759
}
5860

@@ -63,7 +65,9 @@ export function onBeforeRouteLeave(leaveGuard: NavigationGuard) {
6365

6466
if (!activeRecord) {
6567
__DEV__ &&
66-
warn('onBeforeRouteLeave must be called at the top of a setup function')
68+
warn(
69+
'No active route record was found. Are you missing a <router-view> component?'
70+
)
6771
return
6872
}
6973

@@ -79,7 +83,9 @@ export function onBeforeRouteLeave(leaveGuard: NavigationGuard) {
7983
*/
8084
export function onBeforeRouteUpdate(updateGuard: NavigationGuard) {
8185
if (__DEV__ && !getCurrentInstance()) {
82-
warn('onBeforeRouteUpdate must be called at the top of a setup function')
86+
warn(
87+
'getCurrentInstance() returned null. onBeforeRouteUpdate() must be called at the top of a setup function'
88+
)
8389
return
8490
}
8591

@@ -90,7 +96,9 @@ export function onBeforeRouteUpdate(updateGuard: NavigationGuard) {
9096

9197
if (!activeRecord) {
9298
__DEV__ &&
93-
warn('onBeforeRouteUpdate must be called at the top of a setup function')
99+
warn(
100+
'No active route record was found. Are you missing a <router-view> component?'
101+
)
94102
return
95103
}
96104

0 commit comments

Comments
 (0)