1 | import { r as registerInstance, h, g as getElement } from './stencilrouter-1307249c.js';
|
2 | import { A as ActiveRouter } from './chunk-cfc6485e.js';
|
3 | import { m as matchPath } from './chunk-8fc41abb.js';
|
4 | import './chunk-d2e78d53.js';
|
5 | import { i as isModifiedEvent } from './chunk-4eecdc1a.js';
|
6 |
|
7 | const getUrl = (url, root) => {
|
8 |
|
9 | if (url.charAt(0) == '/' && root.charAt(root.length - 1) == '/') {
|
10 | return root.slice(0, root.length - 1) + url;
|
11 | }
|
12 | return root + url;
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | class RouteLink {
|
20 | constructor(hostRef) {
|
21 | registerInstance(this, hostRef);
|
22 | this.unsubscribe = () => { return; };
|
23 | this.activeClass = 'link-active';
|
24 | this.exact = false;
|
25 | this.strict = true;
|
26 | |
27 |
|
28 |
|
29 | this.custom = 'a';
|
30 | this.match = null;
|
31 | }
|
32 | componentWillLoad() {
|
33 | this.computeMatch();
|
34 | }
|
35 |
|
36 | computeMatch() {
|
37 | if (this.location) {
|
38 | this.match = matchPath(this.location.pathname, {
|
39 | path: this.urlMatch || this.url,
|
40 | exact: this.exact,
|
41 | strict: this.strict
|
42 | });
|
43 | }
|
44 | }
|
45 | handleClick(e) {
|
46 | if (isModifiedEvent(e) || !this.history || !this.url || !this.root) {
|
47 | return;
|
48 | }
|
49 | e.preventDefault();
|
50 | return this.history.push(getUrl(this.url, this.root));
|
51 | }
|
52 |
|
53 | render() {
|
54 | let anchorAttributes = {
|
55 | class: {
|
56 | [this.activeClass]: this.match !== null,
|
57 | },
|
58 | onClick: this.handleClick.bind(this)
|
59 | };
|
60 | if (this.anchorClass) {
|
61 | anchorAttributes.class[this.anchorClass] = true;
|
62 | }
|
63 | if (this.custom === 'a') {
|
64 | anchorAttributes = Object.assign({}, anchorAttributes, { href: this.url, title: this.anchorTitle, role: this.anchorRole, tabindex: this.anchorTabIndex, 'aria-haspopup': this.ariaHaspopup, id: this.anchorId, 'aria-posinset': this.ariaPosinset, 'aria-setsize': this.ariaSetsize, 'aria-label': this.ariaLabel });
|
65 | }
|
66 | return (h(this.custom, Object.assign({}, anchorAttributes), h("slot", null)));
|
67 | }
|
68 | get el() { return getElement(this); }
|
69 | static get watchers() { return {
|
70 | "location": ["computeMatch"]
|
71 | }; }
|
72 | }
|
73 | ActiveRouter.injectProps(RouteLink, [
|
74 | 'history',
|
75 | 'location',
|
76 | 'root'
|
77 | ]);
|
78 |
|
79 | export { RouteLink as stencil_route_link };
|