UNPKG

850 BJavaScriptView Raw
1import { r as registerInstance, g as getElement } from './stencilrouter-1307249c.js';
2import { A as ActiveRouter } from './chunk-cfc6485e.js';
3
4// Get the URL for this route link without the root from the router
5const getUrl = (url, root) => {
6 // Don't allow double slashes
7 if (url.charAt(0) == '/' && root.charAt(root.length - 1) == '/') {
8 return root.slice(0, root.length - 1) + url;
9 }
10 return root + url;
11};
12class Redirect {
13 constructor(hostRef) {
14 registerInstance(this, hostRef);
15 }
16 componentWillLoad() {
17 if (this.history && this.root && this.url) {
18 return this.history.replace(getUrl(this.url, this.root));
19 }
20 }
21 get el() { return getElement(this); }
22}
23ActiveRouter.injectProps(Redirect, [
24 'history',
25 'root'
26]);
27
28export { Redirect as stencil_router_redirect };