@lwrjs/router 0.11.1 → 0.11.2
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.
|
@@ -40,12 +40,16 @@ var ServerRouter = class {
|
|
|
40
40
|
this.contextId = Object.freeze(() => void 0);
|
|
41
41
|
this.router = router;
|
|
42
42
|
this.target = target;
|
|
43
|
+
this.handleNavHook = config.handleNavigation;
|
|
43
44
|
this.preNavHook = config.preNavigate;
|
|
44
45
|
this.errorNavHook = config.errorNavigate;
|
|
45
46
|
this.initWires(config.url);
|
|
46
47
|
}
|
|
47
48
|
async navigate(address) {
|
|
48
49
|
if (import_routerUtils.hasDocument) {
|
|
50
|
+
if (this.handleNavHook && !this.handleNavHook(address)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
49
53
|
const url = await this.getValidatedUrl(address);
|
|
50
54
|
if (url) {
|
|
51
55
|
document.location.href = url;
|
|
@@ -2,10 +2,12 @@ import type { RouteChange } from 'lwr/domRouterUtils';
|
|
|
2
2
|
import type { ContextId } from 'lwr/navigation';
|
|
3
3
|
import type { PageReference, Router, RouterConfig, RoutingMatch } from 'lwr/router';
|
|
4
4
|
import type { MessageObject } from 'lwr/routerUtils';
|
|
5
|
-
type
|
|
5
|
+
type HandleNavFunction = (p: PageReference) => boolean;
|
|
6
|
+
type PreNavFunction = (r: RouteChange) => boolean | Promise<boolean>;
|
|
6
7
|
type ErrorNavFunction = (m: MessageObject) => void;
|
|
7
8
|
type ServerRouterConfig = RouterConfig & {
|
|
8
9
|
url?: string;
|
|
10
|
+
handleNavigation?: HandleNavFunction;
|
|
9
11
|
preNavigate?: PreNavFunction;
|
|
10
12
|
errorNavigate?: ErrorNavFunction;
|
|
11
13
|
};
|
|
@@ -13,6 +15,7 @@ export declare class ServerRouter {
|
|
|
13
15
|
router: Router<PageReference | string>;
|
|
14
16
|
target: EventTarget;
|
|
15
17
|
contextId: ContextId;
|
|
18
|
+
handleNavHook?: HandleNavFunction;
|
|
16
19
|
preNavHook?: PreNavFunction;
|
|
17
20
|
errorNavHook?: ErrorNavFunction;
|
|
18
21
|
currentRoute: RoutingMatch | undefined;
|
|
@@ -11,6 +11,7 @@ export class ServerRouter {
|
|
|
11
11
|
this.contextId = Object.freeze(() => undefined);
|
|
12
12
|
this.router = router;
|
|
13
13
|
this.target = target;
|
|
14
|
+
this.handleNavHook = config.handleNavigation;
|
|
14
15
|
this.preNavHook = config.preNavigate;
|
|
15
16
|
this.errorNavHook = config.errorNavigate;
|
|
16
17
|
this.initWires(config.url);
|
|
@@ -22,6 +23,11 @@ export class ServerRouter {
|
|
|
22
23
|
*/
|
|
23
24
|
async navigate(address) {
|
|
24
25
|
if (hasDocument) {
|
|
26
|
+
// invoke the handleNavigation hook, which intercepts the raw page ref
|
|
27
|
+
if (this.handleNavHook && !this.handleNavHook(address)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// continue navigating
|
|
25
31
|
const url = await this.getValidatedUrl(address);
|
|
26
32
|
if (url) {
|
|
27
33
|
// hard navigation
|
|
@@ -13,6 +13,7 @@ export class ServerRouter {
|
|
|
13
13
|
constructor(config, router, target) {
|
|
14
14
|
this.router = router;
|
|
15
15
|
this.target = target;
|
|
16
|
+
this.handleNavHook = config.handleNavigation;
|
|
16
17
|
this.preNavHook = config.preNavigate;
|
|
17
18
|
this.errorNavHook = config.errorNavigate;
|
|
18
19
|
this.initWires(config.url);
|
|
@@ -25,6 +26,12 @@ export class ServerRouter {
|
|
|
25
26
|
*/
|
|
26
27
|
async navigate(address) {
|
|
27
28
|
if (hasDocument) {
|
|
29
|
+
// invoke the handleNavigation hook, which intercepts the raw page ref
|
|
30
|
+
if (this.handleNavHook && !this.handleNavHook(address)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// continue navigating
|
|
28
35
|
const url = await this.getValidatedUrl(address);
|
|
29
36
|
if (url) {
|
|
30
37
|
// hard navigation
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.11.
|
|
8
|
+
"version": "0.11.2",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"test:server": "jest --config ./jest.server.config.cjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lwrjs/client-modules": "0.11.
|
|
57
|
-
"@lwrjs/diagnostics": "0.11.
|
|
58
|
-
"@lwrjs/shared-utils": "0.11.
|
|
56
|
+
"@lwrjs/client-modules": "0.11.2",
|
|
57
|
+
"@lwrjs/diagnostics": "0.11.2",
|
|
58
|
+
"@lwrjs/shared-utils": "0.11.2",
|
|
59
59
|
"ajv": "6.12.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^14.1.0",
|
|
63
|
-
"@lwrjs/fs-watch": "0.11.
|
|
63
|
+
"@lwrjs/fs-watch": "0.11.2",
|
|
64
64
|
"@rollup/plugin-typescript": "^11.1.5",
|
|
65
65
|
"jest": "^26.6.3",
|
|
66
66
|
"rollup": "^2.78.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"utam": "2.2.0-alpha1"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"lwc": "2.x
|
|
72
|
+
"lwc": ">= 2.x"
|
|
73
73
|
},
|
|
74
74
|
"lwc": {
|
|
75
75
|
"modules": [
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"volta": {
|
|
99
99
|
"extends": "../../../package.json"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "290a924d5e6610b54566aec8750895772f06d3aa"
|
|
102
102
|
}
|