UNPKG

3.58 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const __chunk_1 = require('./stencilrouter-a3d77a87.js');
6const __chunk_2 = require('./chunk-94c92d88.js');
7const __chunk_3 = require('./chunk-b786ea51.js');
8require('./chunk-e6311a56.js');
9
10/**
11 * @name Route
12 * @module ionic
13 * @description
14 */
15class 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 // Identify if the current route is a match.
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 // After all children have completed then tell switch
51 // the provided callback will get executed after this route is in view
52 if (typeof this.componentUpdated === 'function') {
53 this.componentUpdated(routeViewOptions);
54 // If this is an independent route and it matches then routes have updated.
55 // If the only change to location is a hash change then do not scroll.
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 // If there is no activeRouter then do not render
69 // Check if this route is in the matching URL (for example, a parent route)
70 if (!this.match || !this.history) {
71 return null;
72 }
73 // component props defined in route
74 // the history api
75 // current match data including params
76 const childProps = Object.assign({}, this.componentProps, { history: this.history, match: this.match });
77 // If there is a routerRender defined then use
78 // that and pass the component and component props with it.
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
100exports.stencil_route = Route;