完成80%
This commit is contained in:
+38
-2
@@ -633,6 +633,34 @@ const assertResultSourceContext = (targetRoute, targetParams, sourcePage) => {
|
||||
}
|
||||
};
|
||||
|
||||
const isImplicitRootOptionalContext = (
|
||||
routeKey,
|
||||
route,
|
||||
existingParams,
|
||||
targetParams,
|
||||
name,
|
||||
sourcePage,
|
||||
) => {
|
||||
if (
|
||||
!ROOT_ROUTE_KEYS.includes(routeKey) ||
|
||||
!route.optionalParams.includes(name) ||
|
||||
hasOwn(existingParams, name) ||
|
||||
!hasOwn(targetParams, name)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const sourceRouteKey = getPageRouteKey(sourcePage);
|
||||
const sourceRoute = getRoute(sourceRouteKey);
|
||||
if (!sourceRoute) return false;
|
||||
const sourceParams = validateRouteParams(
|
||||
sourceRouteKey,
|
||||
getPageParams(sourcePage, sourceRoute),
|
||||
true,
|
||||
).params;
|
||||
return hasOwn(sourceParams, name) && sourceParams[name] === targetParams[name];
|
||||
};
|
||||
|
||||
const returnToValidated = (routeKey, targetParams, result) => {
|
||||
const validatedTarget = validateRouteParams(
|
||||
routeKey,
|
||||
@@ -656,8 +684,16 @@ const returnToValidated = (routeKey, targetParams, result) => {
|
||||
targetIdentity = validatedExisting.params;
|
||||
for (const [name, value] of Object.entries(normalizedTargetParams)) {
|
||||
if (
|
||||
!hasOwn(validatedExisting.params, name) ||
|
||||
validatedExisting.params[name] !== value
|
||||
(!hasOwn(validatedExisting.params, name) ||
|
||||
validatedExisting.params[name] !== value) &&
|
||||
!isImplicitRootOptionalContext(
|
||||
routeKey,
|
||||
route,
|
||||
validatedExisting.params,
|
||||
normalizedTargetParams,
|
||||
name,
|
||||
sourcePage,
|
||||
)
|
||||
) {
|
||||
throw new Error(`${routeKey} 显式目标参数 ${name} 与最近实例不一致`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user