ui5-lib-guard-router 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ui5/build-manifest.json +2 -2
- package/CHANGELOG.md +7 -0
- package/README.md +8 -8
- package/dist/index.d.ts +3 -3
- package/dist/resources/ui5/guard/router/.library +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js +3 -1
- package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.d.ts.map +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.js +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.js.map +1 -1
- package/dist/resources/ui5/guard/router/Router-dbg.js +20 -15
- package/dist/resources/ui5/guard/router/Router-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/Router.d.ts +2 -1
- package/dist/resources/ui5/guard/router/Router.d.ts.map +1 -1
- package/dist/resources/ui5/guard/router/Router.js +1 -1
- package/dist/resources/ui5/guard/router/Router.js.map +1 -1
- package/dist/resources/ui5/guard/router/library-dbg.js +1 -1
- package/dist/resources/ui5/guard/router/library-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/library-preload.js +4 -4
- package/dist/resources/ui5/guard/router/library-preload.js.map +1 -1
- package/dist/resources/ui5/guard/router/library.js +1 -1
- package/dist/resources/ui5/guard/router/library.js.map +1 -1
- package/dist/resources/ui5/guard/router/manifest.json +1 -1
- package/package.json +1 -1
- package/src/GuardPipeline.ts +3 -1
- package/src/Router.ts +19 -18
- package/src/manifest.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
sap.ui.define(["sap/ui/core/Lib","sap/ui/base/DataType","sap/ui/core/library","sap/m/library","./NavigationOutcome"],function(e,i,r,t,u){"use strict";function a(e){return e&&e.__esModule&&typeof e.default!=="undefined"?e.default:e}const n=a(u);const o=e.init({apiVersion:2,name:"ui5.guard.router",version:"1.7.
|
|
1
|
+
sap.ui.define(["sap/ui/core/Lib","sap/ui/base/DataType","sap/ui/core/library","sap/m/library","./NavigationOutcome"],function(e,i,r,t,u){"use strict";function a(e){return e&&e.__esModule&&typeof e.default!=="undefined"?e.default:e}const n=a(u);const o=e.init({apiVersion:2,name:"ui5.guard.router",version:"1.7.1",dependencies:["sap.ui.core","sap.m"],types:["ui5.guard.router.NavigationOutcome"],interfaces:[],controls:[],elements:[],noLibraryCSS:true});i.registerEnum("ui5.guard.router.NavigationOutcome",n);return o});
|
|
2
2
|
//# sourceMappingURL=library.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"library.js","names":["NavigationOutcome","_interopRequireDefault","__NavigationOutcome","library","Lib","init","apiVersion","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS","DataType","registerEnum"],"sources":["./library.ts"],"sourcesContent":["import Lib from \"sap/ui/core/Lib\";\nimport DataType from \"sap/ui/base/DataType\";\nimport \"sap/ui/core/library\";\nimport \"sap/m/library\";\nimport NavigationOutcome from \"./NavigationOutcome\";\n\nconst library = Lib.init({\n\tapiVersion: 2,\n\tname: \"ui5.guard.router\",\n\tversion: \"1.7.
|
|
1
|
+
{"version":3,"file":"library.js","names":["NavigationOutcome","_interopRequireDefault","__NavigationOutcome","library","Lib","init","apiVersion","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS","DataType","registerEnum"],"sources":["./library.ts"],"sourcesContent":["import Lib from \"sap/ui/core/Lib\";\nimport DataType from \"sap/ui/base/DataType\";\nimport \"sap/ui/core/library\";\nimport \"sap/m/library\";\nimport NavigationOutcome from \"./NavigationOutcome\";\n\nconst library = Lib.init({\n\tapiVersion: 2,\n\tname: \"ui5.guard.router\",\n\tversion: \"1.7.1\",\n\tdependencies: [\"sap.ui.core\", \"sap.m\"],\n\ttypes: [\"ui5.guard.router.NavigationOutcome\"],\n\tinterfaces: [],\n\tcontrols: [],\n\telements: [],\n\tnoLibraryCSS: true,\n});\n\nDataType.registerEnum(\"ui5.guard.router.NavigationOutcome\", NavigationOutcome);\n\nexport default library;\n"],"mappings":"6OAIOA,EAAiBC,EAAAC,GAExB,MAAMC,EAAUC,EAAIC,KAAK,CACxBC,WAAY,EACZC,KAAM,mBACNC,QAAS,QACTC,aAAc,CAAC,cAAe,SAC9BC,MAAO,CAAC,sCACRC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,OAGfC,EAASC,aAAa,qCAAsChB,GAAmB,OAEhEG,CAAO","ignoreList":[]}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"id": "ui5.guard.router",
|
|
5
5
|
"type": "library",
|
|
6
6
|
"applicationVersion": {
|
|
7
|
-
"version": "1.7.
|
|
7
|
+
"version": "1.7.1"
|
|
8
8
|
},
|
|
9
9
|
"title": "UI5 Router extension with async navigation guards",
|
|
10
10
|
"description": "Extends sap.m.routing.Router with async navigation guards, running before route matching begins."
|
package/package.json
CHANGED
package/src/GuardPipeline.ts
CHANGED
|
@@ -351,13 +351,15 @@ export default class GuardPipeline {
|
|
|
351
351
|
): Promise<R | boolean> {
|
|
352
352
|
let guardIndex = currentIndex;
|
|
353
353
|
try {
|
|
354
|
+
// An aborted navigation discards the result: it is neither validated nor followed by the next guard.
|
|
354
355
|
const result = await pendingResult;
|
|
356
|
+
if (context.signal.aborted) return false;
|
|
355
357
|
if (result !== true) return onBlock(result);
|
|
356
358
|
|
|
357
359
|
for (let i = currentIndex + 1; i < guards.length; i++) {
|
|
358
|
-
if (context.signal.aborted) return false;
|
|
359
360
|
guardIndex = i;
|
|
360
361
|
const nextResult = await guards[i](context);
|
|
362
|
+
if (context.signal.aborted) return false;
|
|
361
363
|
if (nextResult !== true) return onBlock(nextResult);
|
|
362
364
|
}
|
|
363
365
|
return true;
|
package/src/Router.ts
CHANGED
|
@@ -610,25 +610,18 @@ export default class Router extends MobileRouter implements GuardRouter {
|
|
|
610
610
|
*/
|
|
611
611
|
addRouteGuard(routeName: string, guard: GuardFn | RouteGuardConfig): this {
|
|
612
612
|
if (isRouteGuardConfig(guard)) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (guard.beforeEnter !== undefined) {
|
|
617
|
-
hasHandler = true;
|
|
618
|
-
if (this._isFn(guard.beforeEnter, "addRouteGuard", routeName)) {
|
|
619
|
-
this._pipeline.addEnterGuard(routeName, guard.beforeEnter);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
if (guard.beforeLeave !== undefined) {
|
|
623
|
-
hasHandler = true;
|
|
624
|
-
if (this._isFn(guard.beforeLeave, "addRouteGuard", routeName)) {
|
|
625
|
-
this._pipeline.addLeaveGuard(routeName, guard.beforeLeave);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (!hasHandler) {
|
|
613
|
+
const { beforeEnter, beforeLeave } = guard;
|
|
614
|
+
if (beforeEnter === undefined && beforeLeave === undefined) {
|
|
630
615
|
Log.info("addRouteGuard: config has no beforeEnter or beforeLeave", routeName, LOG_COMPONENT);
|
|
616
|
+
return this;
|
|
631
617
|
}
|
|
618
|
+
// As for a guard function: the route is checked only when something is registered.
|
|
619
|
+
const enter = beforeEnter !== undefined && this._isFn(beforeEnter, "addRouteGuard", routeName);
|
|
620
|
+
const leave = beforeLeave !== undefined && this._isFn(beforeLeave, "addRouteGuard", routeName);
|
|
621
|
+
if (!enter && !leave) return this;
|
|
622
|
+
this._handleUnknownRouteRegistration(routeName, "addRouteGuard");
|
|
623
|
+
if (enter) this._pipeline.addEnterGuard(routeName, beforeEnter);
|
|
624
|
+
if (leave) this._pipeline.addLeaveGuard(routeName, beforeLeave);
|
|
632
625
|
return this;
|
|
633
626
|
}
|
|
634
627
|
if (!this._isFn(guard, "addRouteGuard", routeName)) return this;
|
|
@@ -835,7 +828,8 @@ export default class Router extends MobileRouter implements GuardRouter {
|
|
|
835
828
|
* Fires synchronously after every guard pipeline settlement with
|
|
836
829
|
* a {@link NavigationResult} payload. Unlike the one-shot
|
|
837
830
|
* `navigationSettled()` Promise, this event fires for every
|
|
838
|
-
* navigation outcome without re-registration.
|
|
831
|
+
* navigation outcome without re-registration. It does not fire for the
|
|
832
|
+
* navigation that `destroy()` cancels.
|
|
839
833
|
*
|
|
840
834
|
* @param oData - Application-specific payload passed to the handler as second argument.
|
|
841
835
|
* @param fnFunction - The function to be called when the event occurs.
|
|
@@ -887,6 +881,8 @@ export default class Router extends MobileRouter implements GuardRouter {
|
|
|
887
881
|
for (const resolve of resolvers) {
|
|
888
882
|
resolve(result);
|
|
889
883
|
}
|
|
884
|
+
// No handler runs while destroy() tears the router down; the native destroy() fires no event either.
|
|
885
|
+
if (this._destroyed) return;
|
|
890
886
|
try {
|
|
891
887
|
this.fireEvent("navigationSettled", result);
|
|
892
888
|
} catch (error) {
|
|
@@ -959,6 +955,11 @@ export default class Router extends MobileRouter implements GuardRouter {
|
|
|
959
955
|
replaceOrOptions?: boolean | GuardNavToOptions,
|
|
960
956
|
options?: GuardNavToOptions,
|
|
961
957
|
): this {
|
|
958
|
+
// The guards are gone: code that awaited navigationSettled() may still call navTo().
|
|
959
|
+
if (this._destroyed) {
|
|
960
|
+
Log.warning("navTo: router is destroyed, ignoring", routeName, LOG_COMPONENT);
|
|
961
|
+
return this;
|
|
962
|
+
}
|
|
962
963
|
const { componentTargetInfo, replace, guardOptions } = this._resolveNavToArgs(
|
|
963
964
|
componentTargetInfoOrReplace,
|
|
964
965
|
replaceOrOptions,
|
package/src/manifest.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"id": "ui5.guard.router",
|
|
5
5
|
"type": "library",
|
|
6
6
|
"applicationVersion": {
|
|
7
|
-
"version": "1.7.
|
|
7
|
+
"version": "1.7.1"
|
|
8
8
|
},
|
|
9
9
|
"title": "UI5 Router extension with async navigation guards",
|
|
10
10
|
"description": "Extends sap.m.routing.Router with async navigation guards, running before route matching begins."
|