Skip to content

Commit 92d9812

Browse files
committed
chore: revert guard changes
1 parent 50a675a commit 92d9812

File tree

4 files changed

+38
-68
lines changed

4 files changed

+38
-68
lines changed

packages/router/src/history/common.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ export interface NavigationInformation {
4848
type: NavigationType
4949
direction: NavigationDirection
5050
delta: number
51-
/**
52-
* True if the navigation was triggered by the browser back button.
53-
*/
54-
isBackBrowserButton?: boolean
55-
/**
56-
* True if the navigation was triggered by the browser forward button.
57-
*/
58-
isForwardBrowserButton?: boolean
5951
}
6052

6153
export interface NavigationCallback {

packages/router/src/navigation-api/index.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { App, shallowReactive, shallowRef, unref } from 'vue'
1+
import type { App } from 'vue'
2+
import { shallowReactive, shallowRef, unref } from 'vue'
23
import {
34
parseURL,
45
stringifyURL,
@@ -142,9 +143,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
142143
leavingRecords.reverse(),
143144
'beforeRouteLeave',
144145
to,
145-
from,
146-
undefined,
147-
navigationInfo
146+
from
148147
)
149148

150149
const canceledNavigationCheck = async () => {
@@ -157,7 +156,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
157156
// check global guards beforeEach
158157
guards = []
159158
for (const guard of beforeGuards.list()) {
160-
guards.push(guardToPromiseFn(guard, to, from, { info: navigationInfo }))
159+
guards.push(guardToPromiseFn(guard, to, from))
161160
}
162161
guards.push(canceledNavigationCheck)
163162
await runGuardQueue(guards)
@@ -178,15 +177,9 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
178177
if (record.beforeEnter) {
179178
if (isArray(record.beforeEnter)) {
180179
for (const beforeEnter of record.beforeEnter)
181-
guards.push(
182-
guardToPromiseFn(beforeEnter, to, from, { info: navigationInfo })
183-
)
180+
guards.push(guardToPromiseFn(beforeEnter, to, from))
184181
} else {
185-
guards.push(
186-
guardToPromiseFn(record.beforeEnter, to, from, {
187-
info: navigationInfo,
188-
})
189-
)
182+
guards.push(guardToPromiseFn(record.beforeEnter, to, from))
190183
}
191184
}
192185
}
@@ -203,16 +196,15 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
203196
'beforeRouteEnter',
204197
to,
205198
from,
206-
runWithContext,
207-
navigationInfo
199+
runWithContext
208200
)
209201
guards.push(canceledNavigationCheck)
210202
await runGuardQueue(guards)
211203

212204
// check global guards beforeResolve
213205
guards = []
214206
for (const guard of beforeResolveGuards.list()) {
215-
guards.push(guardToPromiseFn(guard, to, from, { info: navigationInfo }))
207+
guards.push(guardToPromiseFn(guard, to, from))
216208
}
217209
guards.push(canceledNavigationCheck)
218210
await runGuardQueue(guards)
@@ -639,9 +631,9 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
639631
delta > 0
640632
? NavigationDirection.forward
641633
: NavigationDirection.back,
642-
delta,
634+
delta /*,
643635
isBackBrowserButton: delta < 0,
644-
isForwardBrowserButton: delta > 0,
636+
isForwardBrowserButton: delta > 0*/,
645637
}
646638
} else if (
647639
event.navigationType === 'push' ||
@@ -708,9 +700,9 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
708700
type: NavigationType.pop,
709701
direction:
710702
delta > 0 ? NavigationDirection.forward : NavigationDirection.back,
711-
delta,
703+
delta /*,
712704
isBackBrowserButton: delta < 0,
713-
isForwardBrowserButton: delta > 0,
705+
isForwardBrowserButton: delta > 0*/,
714706
}
715707

716708
pendingLocation = to

packages/router/src/navigationGuards.ts

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { matchedRouteKey } from './injectionSymbols'
2222
import { RouteRecordNormalized } from './matcher/types'
2323
import { isESModule, isRouteComponent } from './utils'
2424
import { warn } from './warning'
25-
import { NavigationInformation } from './history/common'
2625

2726
function registerGuard(
2827
record: RouteRecordNormalized,
@@ -107,20 +106,27 @@ export function onBeforeRouteUpdate(updateGuard: NavigationGuard) {
107106
registerGuard(activeRecord, 'updateGuards', updateGuard)
108107
}
109108

110-
interface GuardToPromiseFnOptions {
111-
record?: RouteRecordNormalized
112-
name?: string
113-
runWithContext?: <T>(fn: () => T) => T
114-
info?: NavigationInformation
115-
}
116-
109+
export function guardToPromiseFn(
110+
guard: NavigationGuard,
111+
to: RouteLocationNormalized,
112+
from: RouteLocationNormalizedLoaded
113+
): () => Promise<void>
117114
export function guardToPromiseFn(
118115
guard: NavigationGuard,
119116
to: RouteLocationNormalized,
120117
from: RouteLocationNormalizedLoaded,
121-
options: GuardToPromiseFnOptions = {}
118+
record: RouteRecordNormalized,
119+
name: string,
120+
runWithContext: <T>(fn: () => T) => T
121+
): () => Promise<void>
122+
export function guardToPromiseFn(
123+
guard: NavigationGuard,
124+
to: RouteLocationNormalized,
125+
from: RouteLocationNormalizedLoaded,
126+
record?: RouteRecordNormalized,
127+
name?: string,
128+
runWithContext: <T>(fn: () => T) => T = fn => fn()
122129
): () => Promise<void> {
123-
const { record, name, runWithContext = fn => fn(), info } = options
124130
// keep a reference to the enterCallbackArray to prevent pushing callbacks if a new navigation took place
125131
const enterCallbackArray =
126132
record &&
@@ -173,7 +179,7 @@ export function guardToPromiseFn(
173179
record && record.instances[name!],
174180
to,
175181
from,
176-
__DEV__ ? canOnlyBeCalledOnce(next, to, from, info) : next
182+
__DEV__ ? canOnlyBeCalledOnce(next, to, from) : next
177183
)
178184
)
179185
let guardCall = Promise.resolve(guardReturn)
@@ -208,19 +214,14 @@ export function guardToPromiseFn(
208214
function canOnlyBeCalledOnce(
209215
next: NavigationGuardNext,
210216
to: RouteLocationNormalized,
211-
from: RouteLocationNormalized,
212-
info?: NavigationInformation
217+
from: RouteLocationNormalized
213218
): NavigationGuardNext {
214219
let called = 0
215220
return function () {
216-
if (called++ === 1) {
217-
const showInfo = info
218-
? ` (type=${info.type},direction=${info.direction},delta=${info.delta})`
219-
: ''
221+
if (called++ === 1)
220222
warn(
221-
`The "next" callback was called more than once in one navigation guard when going from "${from.fullPath}" to "${to.fullPath}"${showInfo}. It should be called exactly one time in each navigation guard. This will fail in production.`
223+
`The "next" callback was called more than once in one navigation guard when going from "${from.fullPath}" to "${to.fullPath}". It should be called exactly one time in each navigation guard. This will fail in production.`
222224
)
223-
}
224225
// @ts-expect-error: we put it in the original one because it's easier to check
225226
next._called = true
226227
if (called === 1) next.apply(null, arguments as any)
@@ -234,8 +235,7 @@ export function extractComponentsGuards(
234235
guardType: GuardType,
235236
to: RouteLocationNormalized,
236237
from: RouteLocationNormalizedLoaded,
237-
runWithContext: <T>(fn: () => T) => T = fn => fn(),
238-
info?: NavigationInformation
238+
runWithContext: <T>(fn: () => T) => T = fn => fn()
239239
) {
240240
const guards: Array<() => Promise<void>> = []
241241

@@ -298,12 +298,7 @@ export function extractComponentsGuards(
298298
const guard = options[guardType]
299299
guard &&
300300
guards.push(
301-
guardToPromiseFn(guard, to, from, {
302-
record,
303-
name,
304-
runWithContext,
305-
info,
306-
})
301+
guardToPromiseFn(guard, to, from, record, name, runWithContext)
307302
)
308303
} else {
309304
// start requesting the chunk already
@@ -339,12 +334,7 @@ export function extractComponentsGuards(
339334

340335
return (
341336
guard &&
342-
guardToPromiseFn(guard, to, from, {
343-
record,
344-
name,
345-
runWithContext,
346-
info,
347-
})()
337+
guardToPromiseFn(guard, to, from, record, name, runWithContext)()
348338
)
349339
})
350340
)

packages/router/src/typed-routes/navigation-guards.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
import type { TypesConfig } from '../config'
88
import type { NavigationFailure } from '../errors'
99
import { ComponentPublicInstance } from 'vue'
10-
import { NavigationInformation } from '../history/common'
1110

1211
/**
1312
* Return types for a Navigation Guard. Based on `TypesConfig`
@@ -26,8 +25,7 @@ export interface NavigationGuardWithThis<T> {
2625
to: RouteLocationNormalized,
2726
from: RouteLocationNormalizedLoaded,
2827
// intentionally not typed to make people use the return
29-
next: NavigationGuardNext,
30-
info?: NavigationInformation
28+
next: NavigationGuardNext
3129
): _Awaitable<NavigationGuardReturn>
3230
}
3331

@@ -43,8 +41,7 @@ export interface _NavigationGuardResolved {
4341
to: RouteLocationNormalizedLoaded,
4442
from: RouteLocationNormalizedLoaded,
4543
// intentionally not typed to make people use the return
46-
next: NavigationGuardNext,
47-
info?: NavigationInformation
44+
next: NavigationGuardNext
4845
): _Awaitable<NavigationGuardReturn>
4946
}
5047

@@ -56,8 +53,7 @@ export interface NavigationGuard {
5653
to: RouteLocationNormalized,
5754
from: RouteLocationNormalizedLoaded,
5855
// intentionally not typed to make people use the return
59-
next: NavigationGuardNext,
60-
info?: NavigationInformation
56+
next: NavigationGuardNext
6157
): _Awaitable<NavigationGuardReturn>
6258
}
6359

0 commit comments

Comments
 (0)