UNPKG

@stencil/router

Version:
101 lines (96 loc) 3.58 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const __chunk_1 = require('./stencilrouter-a3d77a87.js'); const __chunk_2 = require('./chunk-94c92d88.js'); const __chunk_3 = require('./chunk-b786ea51.js'); require('./chunk-e6311a56.js'); /** * @name Route * @module ionic * @description */ class Route { constructor(hostRef) { __chunk_1.registerInstance(this, hostRef); this.group = null; this.match = null; this.componentProps = {}; this.exact = false; this.scrollOnNextRender = false; this.previousMatch = null; } // Identify if the current route is a match. computeMatch(newLocation) { const isGrouped = this.group != null || (this.el.parentElement != null && this.el.parentElement.tagName.toLowerCase() === 'stencil-route-switch'); if (!newLocation || isGrouped) { return; } this.previousMatch = this.match; return this.match = __chunk_3.matchPath(newLocation.pathname, { path: this.url, exact: this.exact, strict: true }); } async loadCompleted() { let routeViewOptions = {}; if (this.history && this.history.location.hash) { routeViewOptions = { scrollToId: this.history.location.hash.substr(1) }; } else if (this.scrollTopOffset) { routeViewOptions = { scrollTopOffset: this.scrollTopOffset }; } // After all children have completed then tell switch // the provided callback will get executed after this route is in view if (typeof this.componentUpdated === 'function') { this.componentUpdated(routeViewOptions); // If this is an independent route and it matches then routes have updated. // If the only change to location is a hash change then do not scroll. } else if (this.match && !__chunk_3.matchesAreEqual(this.match, this.previousMatch) && this.routeViewsUpdated) { this.routeViewsUpdated(routeViewOptions); } } async componentDidUpdate() { await this.loadCompleted(); } async componentDidLoad() { await this.loadCompleted(); } render() { // If there is no activeRouter then do not render // Check if this route is in the matching URL (for example, a parent route) if (!this.match || !this.history) { return null; } // component props defined in route // the history api // current match data including params const childProps = Object.assign({}, this.componentProps, { history: this.history, match: this.match }); // If there is a routerRender defined then use // that and pass the component and component props with it. if (this.routeRender) { return this.routeRender(Object.assign({}, childProps, { component: this.component })); } if (this.component) { const ChildComponent = this.component; return (__chunk_1.h(ChildComponent, Object.assign({}, childProps))); } } get el() { return __chunk_1.getElement(this); } static get watchers() { return { "location": ["computeMatch"] }; } static get style() { return "stencil-route.inactive{display:none}"; } } __chunk_2.ActiveRouter.injectProps(Route, [ 'location', 'history', 'historyType', 'routeViewsUpdated' ]); exports.stencil_route = Route;