@ossy/router 0.0.1-beta.1 → 0.0.1-beta.3
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/build/esm/router.js +6 -10
- package/package.json +13 -3
package/build/esm/router.js
CHANGED
|
@@ -20,31 +20,25 @@ class Router {
|
|
|
20
20
|
return (_a = this.pages.find(page => page.id === id)) !== null && _a !== void 0 ? _a : this.pages.find(page => page.id === '404');
|
|
21
21
|
}
|
|
22
22
|
getPageByUrl(_url) {
|
|
23
|
-
var _a
|
|
24
|
-
|
|
25
|
-
console.log('[Router][getPageByUrl()] this.pages?.length', (_a = this.pages) === null || _a === void 0 ? void 0 : _a.length);
|
|
26
|
-
if (typeof _url !== 'string' || ((_b = this.pages) === null || _b === void 0 ? void 0 : _b.length) === 0)
|
|
23
|
+
var _a;
|
|
24
|
+
if (typeof _url !== 'string' || ((_a = this.pages) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
27
25
|
return;
|
|
28
26
|
let url;
|
|
29
27
|
try {
|
|
30
28
|
url = new URL(_url);
|
|
31
29
|
}
|
|
32
|
-
catch (
|
|
30
|
+
catch (_b) {
|
|
33
31
|
// If url is not valid, try to parse it with localhost.com fince URL needs domain, but it wont be used
|
|
34
32
|
url = new URL(_url, 'http://localhost.com');
|
|
35
33
|
}
|
|
36
|
-
console.log('[Router][getPageByUrl()] url', url);
|
|
37
34
|
const pathname = padWithSlash(url.pathname);
|
|
38
35
|
const pathnameParts = pathname.split('/').filter(x => !!x);
|
|
39
|
-
console.log('[Router][getPageByUrl()] pathname', pathname);
|
|
40
|
-
console.log('[Router][getPageByUrl()] pathnameParts', pathnameParts);
|
|
41
36
|
const exactMatch = this.pages.find(page => {
|
|
42
37
|
const paths = typeof page.path === 'string'
|
|
43
38
|
? [page.path]
|
|
44
39
|
: Object.entries(page.path).map(([language, path]) => `/${language}${path}`);
|
|
45
40
|
return paths.map(padWithSlash).includes(pathname);
|
|
46
41
|
});
|
|
47
|
-
console.log('[Router][getPageByUrl()] exactMatch', exactMatch);
|
|
48
42
|
if (exactMatch)
|
|
49
43
|
return exactMatch;
|
|
50
44
|
const dynamicMatch = this.pages.find(page => {
|
|
@@ -64,7 +58,6 @@ class Router {
|
|
|
64
58
|
}, '/'));
|
|
65
59
|
return matchContenders.includes(pathname);
|
|
66
60
|
});
|
|
67
|
-
console.log('[Router][getPageByUrl()] dynamicMatch', dynamicMatch);
|
|
68
61
|
return dynamicMatch;
|
|
69
62
|
}
|
|
70
63
|
getParamsFromUrl(_url) {
|
|
@@ -126,6 +119,9 @@ class Router {
|
|
|
126
119
|
if (typeof pathnameTemplate === 'string') {
|
|
127
120
|
if (!params)
|
|
128
121
|
return pathnameTemplate;
|
|
122
|
+
if (!pathnameTemplate.includes(':')) {
|
|
123
|
+
return pathnameTemplate;
|
|
124
|
+
}
|
|
129
125
|
return pathnameTemplate
|
|
130
126
|
.split('/')
|
|
131
127
|
.filter(x => !!x)
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.1-beta.3",
|
|
4
|
+
"description": "Base router built for multi-language support with localized paths",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"router",
|
|
7
|
+
"route",
|
|
8
|
+
"routing",
|
|
9
|
+
"link",
|
|
10
|
+
"server",
|
|
11
|
+
"prerendering",
|
|
12
|
+
"href",
|
|
13
|
+
"anchor",
|
|
14
|
+
"server"
|
|
15
|
+
],
|
|
5
16
|
"type": "module",
|
|
6
17
|
"source": "src/public.index.ts",
|
|
7
18
|
"module": "build/esm/public.index.js",
|
|
@@ -17,7 +28,6 @@
|
|
|
17
28
|
"test": "jest --verbose",
|
|
18
29
|
"test:watch": "jest --watch"
|
|
19
30
|
},
|
|
20
|
-
"keywords": [],
|
|
21
31
|
"author": "",
|
|
22
32
|
"license": "ISC",
|
|
23
33
|
"devDependencies": {
|