@rxdi/router 0.7.219 → 0.7.221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/decorators.d.ts +1 -2
- package/dist/decorators.js +1 -1
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.js +11 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/injection.tokens.d.ts +23 -16
- package/dist/injection.tokens.js +3 -1
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js +6 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/{slot → lib}/index.js +6 -4
- package/dist/lib/path-to-regexp.d.ts +6 -0
- package/dist/lib/path-to-regexp.js +228 -0
- package/dist/lib/resolver.d.ts +70 -0
- package/dist/lib/resolver.js +426 -0
- package/dist/{vaadin/vaadin-router.d.ts → lib/router.d.ts} +98 -201
- package/dist/lib/router.js +833 -0
- package/dist/lib/triggers.d.ts +6 -0
- package/dist/lib/triggers.js +98 -0
- package/dist/lib/types.d.ts +134 -0
- package/dist/lib/types.js +6 -0
- package/dist/lib/utils.d.ts +20 -0
- package/dist/lib/utils.js +155 -0
- package/dist/not-found.component.js +3 -3
- package/dist/outlet.d.ts +7 -62
- package/dist/outlet.js +15 -84
- package/dist/router.component.d.ts +3 -3
- package/dist/router.component.js +4 -4
- package/package.json +3 -3
- package/dist/slot/index.d.ts +0 -8
- package/dist/slot/slot.d.ts +0 -11
- package/dist/slot/slot.js +0 -44
- package/dist/vaadin/vaadin-router.js +0 -2065
- package/slot/index.d.ts +0 -8
- package/slot/index.js +0 -8
- package/slot/slot.d.ts +0 -11
- package/slot/slot.js +0 -45
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NavigationTrigger } from './types';
|
|
2
|
+
export declare function RouterGlobalClickHandler(event: MouseEvent): void;
|
|
3
|
+
export declare const CLICK: NavigationTrigger;
|
|
4
|
+
export declare function RouterGlobalPopstateHandler(event: PopStateEvent): void;
|
|
5
|
+
export declare const POPSTATE: NavigationTrigger;
|
|
6
|
+
export declare function setNavigationTriggers(newTriggers: NavigationTrigger[]): void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POPSTATE = exports.CLICK = void 0;
|
|
4
|
+
exports.RouterGlobalClickHandler = RouterGlobalClickHandler;
|
|
5
|
+
exports.RouterGlobalPopstateHandler = RouterGlobalPopstateHandler;
|
|
6
|
+
exports.setNavigationTriggers = setNavigationTriggers;
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
// IE Polyfill for PopStateEvent
|
|
9
|
+
const isIE = /Trident/.test(navigator.userAgent);
|
|
10
|
+
if (isIE && !(0, utils_1.isFunction)(window.PopStateEvent)) {
|
|
11
|
+
window.PopStateEvent = function (inType, params) {
|
|
12
|
+
params = params || {};
|
|
13
|
+
const e = document.createEvent('Event');
|
|
14
|
+
e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
|
|
15
|
+
e.state = params.state || null;
|
|
16
|
+
return e;
|
|
17
|
+
};
|
|
18
|
+
window.PopStateEvent.prototype = window.Event
|
|
19
|
+
.prototype;
|
|
20
|
+
}
|
|
21
|
+
function RouterGlobalClickHandler(event) {
|
|
22
|
+
if (event.defaultPrevented) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (event.button !== 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let anchor = event.target;
|
|
32
|
+
const path = event.composedPath
|
|
33
|
+
? event.composedPath()
|
|
34
|
+
: event.path || [];
|
|
35
|
+
for (let i = 0; i < path.length; i++) {
|
|
36
|
+
const target = path[i];
|
|
37
|
+
if (target.nodeName && target.nodeName.toLowerCase() === 'a') {
|
|
38
|
+
anchor = target;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
while (anchor && anchor.nodeName && anchor.nodeName.toLowerCase() !== 'a') {
|
|
43
|
+
anchor = anchor.parentNode;
|
|
44
|
+
}
|
|
45
|
+
if (!anchor || anchor.nodeName.toLowerCase() !== 'a') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const anchorElement = anchor;
|
|
49
|
+
if (anchorElement.target && anchorElement.target.toLowerCase() !== '_self') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (anchorElement.hasAttribute('download')) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (anchorElement.hasAttribute('router-ignore')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (anchorElement.pathname === window.location.pathname && anchorElement.hash !== '') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const origin = anchorElement.origin || (0, utils_1.getAnchorOrigin)(anchorElement);
|
|
62
|
+
if (origin !== window.location.origin) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const { pathname, search, hash } = anchorElement;
|
|
66
|
+
if ((0, utils_1.fireRouterEvent)('go', { pathname, search, hash })) {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.CLICK = {
|
|
71
|
+
activate() {
|
|
72
|
+
window.document.addEventListener('click', RouterGlobalClickHandler);
|
|
73
|
+
},
|
|
74
|
+
inactivate() {
|
|
75
|
+
window.document.removeEventListener('click', RouterGlobalClickHandler);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
function RouterGlobalPopstateHandler(event) {
|
|
79
|
+
if (event.state === 'router-ignore') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const { pathname, search, hash } = window.location;
|
|
83
|
+
(0, utils_1.fireRouterEvent)('go', { pathname, search, hash });
|
|
84
|
+
}
|
|
85
|
+
exports.POPSTATE = {
|
|
86
|
+
activate() {
|
|
87
|
+
window.addEventListener('popstate', RouterGlobalPopstateHandler);
|
|
88
|
+
},
|
|
89
|
+
inactivate() {
|
|
90
|
+
window.removeEventListener('popstate', RouterGlobalPopstateHandler);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
let triggers = [];
|
|
94
|
+
function setNavigationTriggers(newTriggers) {
|
|
95
|
+
triggers.forEach((trigger) => trigger.inactivate());
|
|
96
|
+
newTriggers.forEach((trigger) => trigger.activate());
|
|
97
|
+
triggers = newTriggers;
|
|
98
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Router } from '.';
|
|
2
|
+
import { Resolver } from './resolver';
|
|
3
|
+
export interface RouteParams {
|
|
4
|
+
[key: string]: string | string[];
|
|
5
|
+
}
|
|
6
|
+
export interface ChainItem {
|
|
7
|
+
path: string;
|
|
8
|
+
route: Route;
|
|
9
|
+
element?: HTMLElement;
|
|
10
|
+
}
|
|
11
|
+
export interface RouteContext {
|
|
12
|
+
pathname: string;
|
|
13
|
+
search?: string;
|
|
14
|
+
hash?: string;
|
|
15
|
+
params: RouteParams;
|
|
16
|
+
keys: PathToken[];
|
|
17
|
+
route: Route;
|
|
18
|
+
chain?: ChainItem[];
|
|
19
|
+
result?: RouteResult;
|
|
20
|
+
next?: (resume?: boolean, parent?: Route, prevResult?: RouteResult | null) => Promise<RouteContext | typeof notFoundResult>;
|
|
21
|
+
resolver?: Resolver;
|
|
22
|
+
redirectFrom?: string;
|
|
23
|
+
__renderId?: number;
|
|
24
|
+
__redirectCount?: number;
|
|
25
|
+
__divergedChainIndex?: number;
|
|
26
|
+
__skipAttach?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface RouterLocation {
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
pathname: string;
|
|
31
|
+
search: string;
|
|
32
|
+
hash: string;
|
|
33
|
+
routes: Route[];
|
|
34
|
+
route: Route | null;
|
|
35
|
+
params: RouteParams;
|
|
36
|
+
redirectFrom?: string;
|
|
37
|
+
getUrl: (userParams?: RouteParams) => string;
|
|
38
|
+
}
|
|
39
|
+
export interface RouteCommands {
|
|
40
|
+
redirect: (path: string) => RedirectResult;
|
|
41
|
+
component: (component: string) => HTMLElement;
|
|
42
|
+
}
|
|
43
|
+
export type RouteAction = (context: RouteContext, commands?: RouteCommands) => RouteResult | Promise<RouteResult> | undefined | Promise<undefined>;
|
|
44
|
+
export type RouteChildren = Route[] | ((context: Omit<RouteContext, 'next'>) => Route[] | Promise<Route[]>);
|
|
45
|
+
export interface RouteBundle {
|
|
46
|
+
module?: string;
|
|
47
|
+
nomodule?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface Route {
|
|
50
|
+
path?: string | string[];
|
|
51
|
+
name?: string;
|
|
52
|
+
component?: string;
|
|
53
|
+
redirect?: string;
|
|
54
|
+
bundle?: string | RouteBundle;
|
|
55
|
+
action?: RouteAction;
|
|
56
|
+
children?: RouteChildren;
|
|
57
|
+
animate?: boolean | {
|
|
58
|
+
leave?: string;
|
|
59
|
+
enter?: string;
|
|
60
|
+
};
|
|
61
|
+
parent?: Route | null;
|
|
62
|
+
__children?: Route[] | RouteChildren | undefined;
|
|
63
|
+
__synthetic?: boolean;
|
|
64
|
+
fullPath?: string;
|
|
65
|
+
}
|
|
66
|
+
export type RouteResult = HTMLElement | RedirectResult | Error | typeof notFoundResult | null | undefined;
|
|
67
|
+
export interface RedirectResult {
|
|
68
|
+
redirect: {
|
|
69
|
+
pathname: string;
|
|
70
|
+
from: string;
|
|
71
|
+
params: RouteParams;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface PreventResult {
|
|
75
|
+
cancel: boolean;
|
|
76
|
+
}
|
|
77
|
+
export interface ResolverOptions {
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
errorHandler?: (error: Error) => RouteResult;
|
|
80
|
+
resolveRoute?: (context: RouteContext) => RouteResult | Promise<RouteResult> | undefined | Promise<undefined>;
|
|
81
|
+
context?: Partial<RouteContext>;
|
|
82
|
+
}
|
|
83
|
+
export type RouterOptions = ResolverOptions;
|
|
84
|
+
export interface NavigationTrigger {
|
|
85
|
+
activate: () => void;
|
|
86
|
+
inactivate: () => void;
|
|
87
|
+
}
|
|
88
|
+
export interface PathToken {
|
|
89
|
+
name: string | number;
|
|
90
|
+
prefix: string;
|
|
91
|
+
delimiter: string;
|
|
92
|
+
optional: boolean;
|
|
93
|
+
repeat: boolean;
|
|
94
|
+
partial: boolean;
|
|
95
|
+
pattern: string;
|
|
96
|
+
}
|
|
97
|
+
export interface PathRegexp {
|
|
98
|
+
keys: PathToken[];
|
|
99
|
+
pattern: RegExp;
|
|
100
|
+
}
|
|
101
|
+
export interface MatchResult {
|
|
102
|
+
path: string;
|
|
103
|
+
keys: PathToken[];
|
|
104
|
+
params: RouteParams;
|
|
105
|
+
route?: Route;
|
|
106
|
+
}
|
|
107
|
+
export interface PathToRegexpOptions {
|
|
108
|
+
sensitive?: boolean;
|
|
109
|
+
strict?: boolean;
|
|
110
|
+
end?: boolean;
|
|
111
|
+
start?: boolean;
|
|
112
|
+
delimiter?: string;
|
|
113
|
+
endsWith?: string | string[];
|
|
114
|
+
delimiters?: string;
|
|
115
|
+
}
|
|
116
|
+
export interface CompileOptions {
|
|
117
|
+
encode?: (value: string, token: PathToken) => string;
|
|
118
|
+
}
|
|
119
|
+
export interface MatchIterator {
|
|
120
|
+
next: (routeToSkip?: Route) => IteratorResult<MatchResult, undefined>;
|
|
121
|
+
}
|
|
122
|
+
export type UrlGenerator = (routeName: string, params?: RouteParams) => string;
|
|
123
|
+
export interface GenerateUrlsOptions {
|
|
124
|
+
encode?: (value: string, token: PathToken) => string;
|
|
125
|
+
stringifyQueryParams?: (params: Record<string, unknown>) => string;
|
|
126
|
+
}
|
|
127
|
+
export interface HTMLElementWithLocation extends HTMLElement {
|
|
128
|
+
location?: RouterLocation;
|
|
129
|
+
onBeforeEnter?: (location: RouterLocation, commands: Record<string, unknown>, router: Router) => PreventResult | RedirectResult | void | Promise<PreventResult | RedirectResult | void>;
|
|
130
|
+
onBeforeLeave?: (location: RouterLocation, commands: Record<string, unknown>, router: Router) => PreventResult | RedirectResult | void | Promise<PreventResult | RedirectResult | void>;
|
|
131
|
+
onAfterEnter?: (location: RouterLocation, commands: Record<string, unknown>, resolver: Resolver) => void;
|
|
132
|
+
onAfterLeave?: (location: RouterLocation, commands: Record<string, unknown>, resolver: Resolver) => void;
|
|
133
|
+
}
|
|
134
|
+
export declare const notFoundResult: {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Router } from './router';
|
|
2
|
+
import { Route, RouteBundle, RouteContext } from './types';
|
|
3
|
+
export declare function toArray<T>(objectOrArray: T | T[]): T[];
|
|
4
|
+
export declare function log(msg: string): string;
|
|
5
|
+
export declare function logValue(value: unknown): string;
|
|
6
|
+
export declare function ensureBundle(src: string): void;
|
|
7
|
+
export declare function isObject(o: unknown): o is Record<string, unknown>;
|
|
8
|
+
export declare function isFunction(f: unknown): f is Function;
|
|
9
|
+
export declare function isString(s: unknown): s is string;
|
|
10
|
+
export declare function ensureRoute(route: Route): void;
|
|
11
|
+
export declare function ensureRoutes(routes: Route | Route[]): void;
|
|
12
|
+
export declare function loadScript(src: string, key?: string): Promise<Event | void>;
|
|
13
|
+
export declare function loadBundle(bundle: string | RouteBundle): Promise<void>;
|
|
14
|
+
export declare function fireRouterEvent(type: string, detail: Partial<HTMLAnchorElement> | Partial<Location> | Partial<Router>): boolean;
|
|
15
|
+
export declare function getNotFoundError(context: RouteContext): Error & {
|
|
16
|
+
context: RouteContext;
|
|
17
|
+
code: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function getAnchorOrigin(anchor: HTMLAnchorElement): string;
|
|
20
|
+
export declare function runCallbackIfPossible<T extends unknown[], R>(callback: ((...args: T) => R) | undefined, args: T, thisArg: unknown): R | undefined;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toArray = toArray;
|
|
4
|
+
exports.log = log;
|
|
5
|
+
exports.logValue = logValue;
|
|
6
|
+
exports.ensureBundle = ensureBundle;
|
|
7
|
+
exports.isObject = isObject;
|
|
8
|
+
exports.isFunction = isFunction;
|
|
9
|
+
exports.isString = isString;
|
|
10
|
+
exports.ensureRoute = ensureRoute;
|
|
11
|
+
exports.ensureRoutes = ensureRoutes;
|
|
12
|
+
exports.loadScript = loadScript;
|
|
13
|
+
exports.loadBundle = loadBundle;
|
|
14
|
+
exports.fireRouterEvent = fireRouterEvent;
|
|
15
|
+
exports.getNotFoundError = getNotFoundError;
|
|
16
|
+
exports.getAnchorOrigin = getAnchorOrigin;
|
|
17
|
+
exports.runCallbackIfPossible = runCallbackIfPossible;
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
function toArray(objectOrArray) {
|
|
20
|
+
objectOrArray = objectOrArray || [];
|
|
21
|
+
return Array.isArray(objectOrArray) ? objectOrArray : [objectOrArray];
|
|
22
|
+
}
|
|
23
|
+
function log(msg) {
|
|
24
|
+
return `[Router] ${msg}`;
|
|
25
|
+
}
|
|
26
|
+
function logValue(value) {
|
|
27
|
+
if (typeof value !== 'object') {
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
const stringType = Object.prototype.toString.call(value).match(/ (.*)\]$/)[1];
|
|
31
|
+
if (stringType === 'Object' || stringType === 'Array') {
|
|
32
|
+
return `${stringType} ${JSON.stringify(value)}`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return stringType;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function ensureBundle(src) {
|
|
39
|
+
if (!src.match(/.+\.[m]?js$/)) {
|
|
40
|
+
throw new Error(log(`Unsupported type for bundle "${src}": .js or .mjs expected.`));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isObject(o) {
|
|
44
|
+
return typeof o === 'object' && !!o;
|
|
45
|
+
}
|
|
46
|
+
function isFunction(f) {
|
|
47
|
+
return typeof f === 'function';
|
|
48
|
+
}
|
|
49
|
+
function isString(s) {
|
|
50
|
+
return typeof s === 'string';
|
|
51
|
+
}
|
|
52
|
+
function ensureRoute(route) {
|
|
53
|
+
if (!route || !isString(route.path)) {
|
|
54
|
+
throw new Error(log(`Expected route config to be an object with a "path" string property, or an array of such objects`));
|
|
55
|
+
}
|
|
56
|
+
const bundle = route.bundle;
|
|
57
|
+
const stringKeys = ['component', 'redirect', 'bundle'];
|
|
58
|
+
if (!isFunction(route.action) &&
|
|
59
|
+
!Array.isArray(route.children) &&
|
|
60
|
+
!isFunction(route.children) &&
|
|
61
|
+
!isObject(bundle) &&
|
|
62
|
+
!stringKeys.some((key) => isString(route[key]))) {
|
|
63
|
+
throw new Error(log(`Expected route config "${route.path}" to include either "${stringKeys.join('", "')}" ` +
|
|
64
|
+
`or "action" function but none found.`));
|
|
65
|
+
}
|
|
66
|
+
if (bundle) {
|
|
67
|
+
if (isString(bundle)) {
|
|
68
|
+
ensureBundle(bundle);
|
|
69
|
+
}
|
|
70
|
+
else if (!constants_1.bundleKeys.some((key) => key in bundle)) {
|
|
71
|
+
throw new Error(log('Expected route bundle to include either "' + constants_1.NOMODULE + '" or "' + constants_1.MODULE + '" keys, or both'));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
constants_1.bundleKeys.forEach((key) => key in bundle && ensureBundle(bundle[key]));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (route.redirect) {
|
|
78
|
+
['bundle', 'component'].forEach((overriddenProp) => {
|
|
79
|
+
if (overriddenProp in route) {
|
|
80
|
+
console.warn(log(`Route config "${route.path}" has both "redirect" and "${overriddenProp}" properties, ` +
|
|
81
|
+
`and "redirect" will always override the latter. Did you mean to only use "${overriddenProp}"?`));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function ensureRoutes(routes) {
|
|
87
|
+
toArray(routes).forEach((route) => ensureRoute(route));
|
|
88
|
+
}
|
|
89
|
+
function loadScript(src, key) {
|
|
90
|
+
let script = document.head.querySelector('script[src="' + src + '"][async]');
|
|
91
|
+
if (!script) {
|
|
92
|
+
script = document.createElement('script');
|
|
93
|
+
script.setAttribute('src', src);
|
|
94
|
+
if (key === constants_1.MODULE) {
|
|
95
|
+
script.setAttribute('type', constants_1.MODULE);
|
|
96
|
+
}
|
|
97
|
+
else if (key === constants_1.NOMODULE) {
|
|
98
|
+
script.setAttribute(constants_1.NOMODULE, '');
|
|
99
|
+
}
|
|
100
|
+
script.async = true;
|
|
101
|
+
}
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
script['onreadystatechange'] = script.onload = (e) => {
|
|
104
|
+
script.__dynamicImportLoaded = true;
|
|
105
|
+
resolve(e);
|
|
106
|
+
};
|
|
107
|
+
script.onerror = (e) => {
|
|
108
|
+
if (script.parentNode) {
|
|
109
|
+
script.parentNode.removeChild(script);
|
|
110
|
+
}
|
|
111
|
+
reject(e);
|
|
112
|
+
};
|
|
113
|
+
if (script.parentNode === null) {
|
|
114
|
+
document.head.appendChild(script);
|
|
115
|
+
}
|
|
116
|
+
else if (script.__dynamicImportLoaded) {
|
|
117
|
+
resolve();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function loadBundle(bundle) {
|
|
122
|
+
if (isString(bundle)) {
|
|
123
|
+
return loadScript(bundle).then(() => {
|
|
124
|
+
//
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return Promise.race(constants_1.bundleKeys.filter((key) => key in bundle).map((key) => loadScript(bundle[key], key))).then(() => {
|
|
129
|
+
//
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function fireRouterEvent(type, detail) {
|
|
134
|
+
return !window.dispatchEvent(new CustomEvent(`router-${type}`, { cancelable: type === 'go', detail }));
|
|
135
|
+
}
|
|
136
|
+
function getNotFoundError(context) {
|
|
137
|
+
const error = new Error(log(`Page not found (${context.pathname})`));
|
|
138
|
+
error.context = context;
|
|
139
|
+
error.code = 404;
|
|
140
|
+
return error;
|
|
141
|
+
}
|
|
142
|
+
function getAnchorOrigin(anchor) {
|
|
143
|
+
const port = anchor.port;
|
|
144
|
+
const protocol = anchor.protocol;
|
|
145
|
+
const defaultHttp = protocol === 'http:' && port === '80';
|
|
146
|
+
const defaultHttps = protocol === 'https:' && port === '443';
|
|
147
|
+
const host = defaultHttp || defaultHttps ? anchor.hostname : anchor.host;
|
|
148
|
+
return `${protocol}//${host}`;
|
|
149
|
+
}
|
|
150
|
+
function runCallbackIfPossible(callback, args, thisArg) {
|
|
151
|
+
if (isFunction(callback)) {
|
|
152
|
+
return callback.apply(thisArg, args);
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
@@ -15,9 +15,9 @@ exports.NotFoundComponent = NotFoundComponent = __decorate([
|
|
|
15
15
|
(0, lit_html_1.Component)({
|
|
16
16
|
selector: 'not-found-component-rxdi',
|
|
17
17
|
template: () => (0, lit_html_1.html) `
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
<h1>Not found component!</h1>
|
|
19
|
+
<p>Please check your URL.2222daad</p>
|
|
20
|
+
`,
|
|
21
21
|
})
|
|
22
22
|
], NotFoundComponent);
|
|
23
23
|
exports.NotFoundPathConfig = {
|
package/dist/outlet.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RouterOptions
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { RouterOptions } from './injection.tokens';
|
|
3
|
+
import { Router } from './lib';
|
|
3
4
|
interface Detail extends Event {
|
|
4
5
|
detail: {
|
|
5
6
|
location: {
|
|
@@ -7,81 +8,25 @@ interface Detail extends Event {
|
|
|
7
8
|
};
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
|
-
export declare class Outlet
|
|
11
|
+
export declare class Outlet extends Router {
|
|
11
12
|
private options;
|
|
12
13
|
activePath: string;
|
|
13
14
|
private freeze;
|
|
14
|
-
private
|
|
15
|
+
private subscription;
|
|
15
16
|
constructor(element: Element, options: RouterOptions);
|
|
16
|
-
onSnapshotChange(
|
|
17
|
-
unsubscribe: () => void;
|
|
18
|
-
};
|
|
17
|
+
onSnapshotChange(): Observable<Detail>;
|
|
19
18
|
freezeRouter(): void;
|
|
20
19
|
unfreezeRouter(): void;
|
|
21
20
|
getQueryParams<T>(params: string[]): T;
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param routes: Route<C>[]
|
|
25
|
-
* @returns Route<C>[]
|
|
26
|
-
*/
|
|
27
|
-
setRoutes(routes: Route<C>[]): Promise<Node>;
|
|
28
|
-
/**
|
|
29
|
-
* Takes current routes and set it
|
|
30
|
-
* @param routes: Route<C>[]
|
|
31
|
-
* @returns void
|
|
32
|
-
*/
|
|
33
|
-
setOutlet(outlet: Node): void;
|
|
34
|
-
/**
|
|
35
|
-
* Triggers navigation to a new path. Returns a boolean without waiting until the navigation is complete. Returns true if at least one Vaadin.Router has handled the navigation (was subscribed and had baseUrl matching the pathname argument), otherwise returns false.
|
|
22
|
+
* Triggers navigation to a new path. Returns a boolean without waiting until the navigation is complete. Returns true if at least one Router has handled the navigation (was subscribed and had baseUrl matching the pathname argument), otherwise returns false.
|
|
36
23
|
* @param pathnamea new in-app path
|
|
37
24
|
* @returns void
|
|
38
25
|
*/
|
|
39
26
|
go(path: string): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Vaadin Router supports refferring to routes using string names. You can assign a name to a route using the name property of a route object, then generate URLs for that route using the router.urlForName(name, parameters) helper instance method.
|
|
42
|
-
* @param name — the route name
|
|
43
|
-
* @param parameters — optional object with parameters for substitution in the route path
|
|
44
|
-
*/
|
|
45
|
-
urlForName(url: string, params: any): string;
|
|
46
|
-
/**
|
|
47
|
-
* router.urlForPath(path, parameters) is a helper method that generates a URL for the given route path, optionally performing substitution of parameters.
|
|
48
|
-
* @param path — a string route path defined in express.js syntax
|
|
49
|
-
* @param parameters — optional object with parameters for path substitution
|
|
50
|
-
*/
|
|
51
|
-
urlForPath(path: string, params: any): string;
|
|
52
|
-
/**
|
|
53
|
-
* Returns the current router outlet. The initial value is undefined.
|
|
54
|
-
*/
|
|
55
|
-
getOutlet(): Node;
|
|
56
|
-
/**
|
|
57
|
-
* Inherited from Vaadin.Resolver Returns the current list of routes (as a shallow copy). Adding / removing routes to / from the returned array does not affect the routing config, but modifying the route objects does.
|
|
58
|
-
*/
|
|
59
|
-
getRoutes(): Route<C>[];
|
|
60
|
-
/**
|
|
61
|
-
* Removes all existing routes from the routing config.
|
|
62
|
-
*/
|
|
63
|
-
removeRoutes(): void;
|
|
64
|
-
/**
|
|
65
|
-
* Asynchronously resolves the given pathname and renders the resolved route component into the router outlet. If no router outlet is set at the time of calling this method, or at the time when the route resolution is completed, a TypeError is thrown.
|
|
66
|
-
* Returns a promise that is fulfilled with the router outlet DOM Node after the route component is created and inserted into the router outlet, or rejected if no route matches the given path.
|
|
67
|
-
* If another render pass is started before the previous one is completed, the result of the previous render pass is ignored.
|
|
68
|
-
* @param pathnameOrContext — the pathname to render or a context object with a pathname property and other properties to pass to the resolver.
|
|
69
|
-
* @param shouldUpdateHistory
|
|
70
|
-
*/
|
|
71
|
-
render(pathnameOrContext: string | {
|
|
72
|
-
pathname: string;
|
|
73
|
-
search: string;
|
|
74
|
-
hash: string;
|
|
75
|
-
}, shouldUpdateHistory: any): Promise<Node>;
|
|
76
|
-
/**
|
|
77
|
-
* Subscribes this instance to navigation events on the window.
|
|
78
|
-
* NOTE: beware of resource leaks. For as long as a router instance is subscribed to navigation events, it won't be garbage collected.
|
|
79
|
-
*/
|
|
80
|
-
subscribe(): void;
|
|
81
27
|
/**
|
|
82
28
|
* Removes the subscription to navigation events created in the subscribe() method.
|
|
83
29
|
*/
|
|
84
30
|
unsubscribe(): void;
|
|
85
|
-
addRoutes(routes: Route<C> | Route<C>[]): Route<C>[];
|
|
86
31
|
}
|
|
87
32
|
export {};
|
package/dist/outlet.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Outlet = void 0;
|
|
4
|
-
const
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
5
6
|
const helpers_1 = require("./helpers");
|
|
6
|
-
|
|
7
|
+
const lib_1 = require("./lib");
|
|
8
|
+
class Outlet extends lib_1.Router {
|
|
7
9
|
constructor(element, options) {
|
|
8
10
|
super(element, options);
|
|
9
11
|
this.options = options;
|
|
10
12
|
this.activePath = '/';
|
|
11
|
-
this.
|
|
13
|
+
this.subscription = this.onSnapshotChange()
|
|
14
|
+
.pipe((0, operators_1.tap)((event) => {
|
|
12
15
|
if (this.options.log) {
|
|
13
16
|
console.log(`You are at '${event.detail.location.pathname}'`);
|
|
14
17
|
}
|
|
15
18
|
this.activePath = event.detail.location.pathname;
|
|
16
|
-
})
|
|
19
|
+
}))
|
|
20
|
+
.subscribe();
|
|
17
21
|
}
|
|
18
|
-
onSnapshotChange(
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
unsubscribe: () => window.removeEventListener('vaadin-router-location-changed', callback),
|
|
22
|
-
};
|
|
22
|
+
onSnapshotChange() {
|
|
23
|
+
return (0, rxjs_1.fromEvent)(window, 'router-location-changed');
|
|
23
24
|
}
|
|
24
25
|
freezeRouter() {
|
|
25
26
|
this.freeze = true;
|
|
@@ -31,23 +32,7 @@ class Outlet extends vaadin_router_1.Router {
|
|
|
31
32
|
return (0, helpers_1.getQueryParams)(params);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param routes: Route<C>[]
|
|
36
|
-
* @returns Route<C>[]
|
|
37
|
-
*/
|
|
38
|
-
setRoutes(routes) {
|
|
39
|
-
return super.setRoutes(routes);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Takes current routes and set it
|
|
43
|
-
* @param routes: Route<C>[]
|
|
44
|
-
* @returns void
|
|
45
|
-
*/
|
|
46
|
-
setOutlet(outlet) {
|
|
47
|
-
super.setOutlet(outlet);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Triggers navigation to a new path. Returns a boolean without waiting until the navigation is complete. Returns true if at least one Vaadin.Router has handled the navigation (was subscribed and had baseUrl matching the pathname argument), otherwise returns false.
|
|
35
|
+
* Triggers navigation to a new path. Returns a boolean without waiting until the navigation is complete. Returns true if at least one Router has handled the navigation (was subscribed and had baseUrl matching the pathname argument), otherwise returns false.
|
|
51
36
|
* @param pathnamea new in-app path
|
|
52
37
|
* @returns void
|
|
53
38
|
*/
|
|
@@ -59,71 +44,17 @@ class Outlet extends vaadin_router_1.Router {
|
|
|
59
44
|
if (this.options.freeze) {
|
|
60
45
|
this.freezeRouter();
|
|
61
46
|
}
|
|
62
|
-
// window.dispatchEvent(new CustomEvent('
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Vaadin Router supports refferring to routes using string names. You can assign a name to a route using the name property of a route object, then generate URLs for that route using the router.urlForName(name, parameters) helper instance method.
|
|
67
|
-
* @param name — the route name
|
|
68
|
-
* @param parameters — optional object with parameters for substitution in the route path
|
|
69
|
-
*/
|
|
70
|
-
urlForName(url, params) {
|
|
71
|
-
return super.urlForName(url, params);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* router.urlForPath(path, parameters) is a helper method that generates a URL for the given route path, optionally performing substitution of parameters.
|
|
75
|
-
* @param path — a string route path defined in express.js syntax
|
|
76
|
-
* @param parameters — optional object with parameters for path substitution
|
|
77
|
-
*/
|
|
78
|
-
urlForPath(path, params) {
|
|
79
|
-
return super.urlForPath(path, params);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns the current router outlet. The initial value is undefined.
|
|
83
|
-
*/
|
|
84
|
-
getOutlet() {
|
|
85
|
-
return super.getOutlet();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Inherited from Vaadin.Resolver Returns the current list of routes (as a shallow copy). Adding / removing routes to / from the returned array does not affect the routing config, but modifying the route objects does.
|
|
89
|
-
*/
|
|
90
|
-
getRoutes() {
|
|
91
|
-
return super.getRoutes();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Removes all existing routes from the routing config.
|
|
95
|
-
*/
|
|
96
|
-
removeRoutes() {
|
|
97
|
-
super.removeRoutes();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Asynchronously resolves the given pathname and renders the resolved route component into the router outlet. If no router outlet is set at the time of calling this method, or at the time when the route resolution is completed, a TypeError is thrown.
|
|
101
|
-
* Returns a promise that is fulfilled with the router outlet DOM Node after the route component is created and inserted into the router outlet, or rejected if no route matches the given path.
|
|
102
|
-
* If another render pass is started before the previous one is completed, the result of the previous render pass is ignored.
|
|
103
|
-
* @param pathnameOrContext — the pathname to render or a context object with a pathname property and other properties to pass to the resolver.
|
|
104
|
-
* @param shouldUpdateHistory
|
|
105
|
-
*/
|
|
106
|
-
render(pathnameOrContext, shouldUpdateHistory) {
|
|
107
|
-
return super.render(pathnameOrContext, shouldUpdateHistory);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Subscribes this instance to navigation events on the window.
|
|
111
|
-
* NOTE: beware of resource leaks. For as long as a router instance is subscribed to navigation events, it won't be garbage collected.
|
|
112
|
-
*/
|
|
113
|
-
subscribe() {
|
|
114
|
-
super.subscribe();
|
|
47
|
+
// window.dispatchEvent(new CustomEvent('router-go', {detail: {pathname: '/to/path'}}));
|
|
48
|
+
return lib_1.Router.go(path);
|
|
115
49
|
}
|
|
116
50
|
/**
|
|
117
51
|
* Removes the subscription to navigation events created in the subscribe() method.
|
|
118
52
|
*/
|
|
119
53
|
unsubscribe() {
|
|
120
|
-
if (this.
|
|
121
|
-
this.
|
|
54
|
+
if (this.subscription) {
|
|
55
|
+
this.subscription.unsubscribe();
|
|
122
56
|
}
|
|
123
57
|
super.unsubscribe();
|
|
124
58
|
}
|
|
125
|
-
addRoutes(routes) {
|
|
126
|
-
return super.addRoutes(routes);
|
|
127
|
-
}
|
|
128
59
|
}
|
|
129
60
|
exports.Outlet = Outlet;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { LitElement } from
|
|
2
|
-
import { Route } from
|
|
1
|
+
import { LitElement } from '@rxdi/lit-html';
|
|
2
|
+
import { Route } from './injection.tokens';
|
|
3
3
|
/**
|
|
4
4
|
* @customElement router-outlet
|
|
5
5
|
*/
|
|
6
6
|
export declare class RouterComponent extends LitElement {
|
|
7
7
|
id: string;
|
|
8
|
-
routes: Route[];
|
|
8
|
+
routes: Route | Route[];
|
|
9
9
|
OnUpdateFirst(): void;
|
|
10
10
|
}
|