1 | import ActiveRouter from '../../global/active-router';
|
2 |
|
3 | const getUrl = (url, root) => {
|
4 |
|
5 | if (url.charAt(0) == '/' && root.charAt(root.length - 1) == '/') {
|
6 | return root.slice(0, root.length - 1) + url;
|
7 | }
|
8 | return root + url;
|
9 | };
|
10 | export class Redirect {
|
11 | componentWillLoad() {
|
12 | if (this.history && this.root && this.url) {
|
13 | return this.history.replace(getUrl(this.url, this.root));
|
14 | }
|
15 | }
|
16 | static get is() { return "stencil-router-redirect"; }
|
17 | static get properties() { return {
|
18 | "history": {
|
19 | "type": "unknown",
|
20 | "mutable": false,
|
21 | "complexType": {
|
22 | "original": "RouterHistory",
|
23 | "resolved": "RouterHistory | undefined",
|
24 | "references": {
|
25 | "RouterHistory": {
|
26 | "location": "import",
|
27 | "path": "../../global/interfaces"
|
28 | }
|
29 | }
|
30 | },
|
31 | "required": false,
|
32 | "optional": true,
|
33 | "docs": {
|
34 | "tags": [],
|
35 | "text": ""
|
36 | }
|
37 | },
|
38 | "root": {
|
39 | "type": "string",
|
40 | "mutable": false,
|
41 | "complexType": {
|
42 | "original": "string",
|
43 | "resolved": "string | undefined",
|
44 | "references": {}
|
45 | },
|
46 | "required": false,
|
47 | "optional": true,
|
48 | "docs": {
|
49 | "tags": [],
|
50 | "text": ""
|
51 | },
|
52 | "attribute": "root",
|
53 | "reflect": false
|
54 | },
|
55 | "url": {
|
56 | "type": "string",
|
57 | "mutable": false,
|
58 | "complexType": {
|
59 | "original": "string",
|
60 | "resolved": "string | undefined",
|
61 | "references": {}
|
62 | },
|
63 | "required": false,
|
64 | "optional": true,
|
65 | "docs": {
|
66 | "tags": [],
|
67 | "text": ""
|
68 | },
|
69 | "attribute": "url",
|
70 | "reflect": false
|
71 | }
|
72 | }; }
|
73 | static get elementRef() { return "el"; }
|
74 | }
|
75 | ActiveRouter.injectProps(Redirect, [
|
76 | 'history',
|
77 | 'root'
|
78 | ]);
|