UNPKG

920 BJavaScriptView 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');
7
8// Get the URL for this route link without the root from the router
9const getUrl = (url, root) => {
10 // Don't allow double slashes
11 if (url.charAt(0) == '/' && root.charAt(root.length - 1) == '/') {
12 return root.slice(0, root.length - 1) + url;
13 }
14 return root + url;
15};
16class Redirect {
17 constructor(hostRef) {
18 __chunk_1.registerInstance(this, hostRef);
19 }
20 componentWillLoad() {
21 if (this.history && this.root && this.url) {
22 return this.history.replace(getUrl(this.url, this.root));
23 }
24 }
25 get el() { return __chunk_1.getElement(this); }
26}
27__chunk_2.ActiveRouter.injectProps(Redirect, [
28 'history',
29 'root'
30]);
31
32exports.stencil_router_redirect = Redirect;