aprog 2.3.1 → 2.3.2
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/package.json +1 -1
- package/src/router.js +26 -4
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -2,6 +2,11 @@ import NotFound from "./NotFound.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ініціалізація роутера.
|
|
5
|
+
* @param routes
|
|
6
|
+
* @param main
|
|
7
|
+
* @param message
|
|
8
|
+
* @param props
|
|
9
|
+
* @returns {Promise<void>}
|
|
5
10
|
*/
|
|
6
11
|
export const router = async ({routes, main, message = "", props = {}}) => {
|
|
7
12
|
const renderRoute = async () => {
|
|
@@ -29,6 +34,8 @@ export const router = async ({routes, main, message = "", props = {}}) => {
|
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Перехід без рендеру.
|
|
37
|
+
* @param path
|
|
38
|
+
* @param props
|
|
32
39
|
*/
|
|
33
40
|
export const navigateTo = (path, props = {}) => {
|
|
34
41
|
window.history.pushState(props, "", path);
|
|
@@ -36,6 +43,9 @@ export const navigateTo = (path, props = {}) => {
|
|
|
36
43
|
|
|
37
44
|
/**
|
|
38
45
|
* Перехід + рендер.
|
|
46
|
+
* @param path
|
|
47
|
+
* @param props
|
|
48
|
+
* @returns {Promise<void>}
|
|
39
49
|
*/
|
|
40
50
|
export const navi = async (path, props = {}) => {
|
|
41
51
|
window.history.pushState(props, "", path);
|
|
@@ -59,6 +69,9 @@ export const navi = async (path, props = {}) => {
|
|
|
59
69
|
* category_id: "15",
|
|
60
70
|
* product_id: "128"
|
|
61
71
|
* }
|
|
72
|
+
* @param routePath
|
|
73
|
+
* @param path
|
|
74
|
+
* @returns {*|null}
|
|
62
75
|
*/
|
|
63
76
|
const matchRoute = (routePath, path) => {
|
|
64
77
|
const keys = [];
|
|
@@ -84,19 +97,28 @@ const matchRoute = (routePath, path) => {
|
|
|
84
97
|
|
|
85
98
|
/**
|
|
86
99
|
* Знаходить поточний route.
|
|
100
|
+
* @param routes
|
|
101
|
+
* @returns {{routeComponent: ((function({colors?: {backgroundColor: string, numberColor: string, textColor: string}, message?: string}): HTMLDivElement)|*), props: {}}|{routeComponent: RTCIceComponent, props: {}}}
|
|
87
102
|
*/
|
|
88
103
|
const useRoutes = (routes) => {
|
|
89
104
|
const path = window.location.pathname;
|
|
90
105
|
|
|
91
106
|
for (const route of routes) {
|
|
92
107
|
const params = matchRoute(route.path, path);
|
|
108
|
+
|
|
93
109
|
if (params !== null) {
|
|
110
|
+
const props = {
|
|
111
|
+
...(window.history.state || {}),
|
|
112
|
+
...params,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (props.title) {
|
|
116
|
+
document.title = props.title;
|
|
117
|
+
}
|
|
118
|
+
|
|
94
119
|
return {
|
|
95
120
|
routeComponent: route.component,
|
|
96
|
-
props
|
|
97
|
-
...(window.history.state || {}),
|
|
98
|
-
...params,
|
|
99
|
-
},
|
|
121
|
+
props,
|
|
100
122
|
};
|
|
101
123
|
}
|
|
102
124
|
}
|