1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const __chunk_1 = require('./stencilrouter-a3d77a87.js');
|
6 | const __chunk_2 = require('./chunk-94c92d88.js');
|
7 | const __chunk_3 = require('./chunk-b786ea51.js');
|
8 | require('./chunk-e6311a56.js');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class Route {
|
16 | constructor(hostRef) {
|
17 | __chunk_1.registerInstance(this, hostRef);
|
18 | this.group = null;
|
19 | this.match = null;
|
20 | this.componentProps = {};
|
21 | this.exact = false;
|
22 | this.scrollOnNextRender = false;
|
23 | this.previousMatch = null;
|
24 | }
|
25 |
|
26 | computeMatch(newLocation) {
|
27 | const isGrouped = this.group != null || (this.el.parentElement != null && this.el.parentElement.tagName.toLowerCase() === 'stencil-route-switch');
|
28 | if (!newLocation || isGrouped) {
|
29 | return;
|
30 | }
|
31 | this.previousMatch = this.match;
|
32 | return this.match = __chunk_3.matchPath(newLocation.pathname, {
|
33 | path: this.url,
|
34 | exact: this.exact,
|
35 | strict: true
|
36 | });
|
37 | }
|
38 | async loadCompleted() {
|
39 | let routeViewOptions = {};
|
40 | if (this.history && this.history.location.hash) {
|
41 | routeViewOptions = {
|
42 | scrollToId: this.history.location.hash.substr(1)
|
43 | };
|
44 | }
|
45 | else if (this.scrollTopOffset) {
|
46 | routeViewOptions = {
|
47 | scrollTopOffset: this.scrollTopOffset
|
48 | };
|
49 | }
|
50 |
|
51 |
|
52 | if (typeof this.componentUpdated === 'function') {
|
53 | this.componentUpdated(routeViewOptions);
|
54 |
|
55 |
|
56 | }
|
57 | else if (this.match && !__chunk_3.matchesAreEqual(this.match, this.previousMatch) && this.routeViewsUpdated) {
|
58 | this.routeViewsUpdated(routeViewOptions);
|
59 | }
|
60 | }
|
61 | async componentDidUpdate() {
|
62 | await this.loadCompleted();
|
63 | }
|
64 | async componentDidLoad() {
|
65 | await this.loadCompleted();
|
66 | }
|
67 | render() {
|
68 |
|
69 |
|
70 | if (!this.match || !this.history) {
|
71 | return null;
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 | const childProps = Object.assign({}, this.componentProps, { history: this.history, match: this.match });
|
77 |
|
78 |
|
79 | if (this.routeRender) {
|
80 | return this.routeRender(Object.assign({}, childProps, { component: this.component }));
|
81 | }
|
82 | if (this.component) {
|
83 | const ChildComponent = this.component;
|
84 | return (__chunk_1.h(ChildComponent, Object.assign({}, childProps)));
|
85 | }
|
86 | }
|
87 | get el() { return __chunk_1.getElement(this); }
|
88 | static get watchers() { return {
|
89 | "location": ["computeMatch"]
|
90 | }; }
|
91 | static get style() { return "stencil-route.inactive{display:none}"; }
|
92 | }
|
93 | __chunk_2.ActiveRouter.injectProps(Route, [
|
94 | 'location',
|
95 | 'history',
|
96 | 'historyType',
|
97 | 'routeViewsUpdated'
|
98 | ]);
|
99 |
|
100 | exports.stencil_route = Route;
|