@gohanfromgoku/ui-kit 0.1.1 → 0.1.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.
|
@@ -15,7 +15,7 @@ const Outlet = ({ routes, page404: Page404Page = Page404 }) => {
|
|
|
15
15
|
const params = extractParamsFromURL(currentpath, active.pathname);
|
|
16
16
|
const queryParams = extractQueryParamsFromURL(href);
|
|
17
17
|
activeRoute.setState({ value: active });
|
|
18
|
-
location.setState({ value: { params, queryParams } });
|
|
18
|
+
location.setState({ value: { params, queryParams, ...window.location } });
|
|
19
19
|
};
|
|
20
20
|
updateLocation();
|
|
21
21
|
window.addEventListener("popstate", updateLocation);
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { globalRoutes } from "./navigation.store";
|
|
1
|
+
import { activeRoute, globalRoutes, location } from "./navigation.store";
|
|
2
|
+
import { extractParamsFromURL } from "./extractParamsFromURL";
|
|
3
|
+
import { extractQueryParamsFromURL } from "./extractQueryParamsFromURL";
|
|
4
|
+
import isRouteMatching from "./isRouteMatching";
|
|
5
|
+
import { Page404 } from "./Page404";
|
|
2
6
|
const createRoutes = (routes) => {
|
|
3
7
|
globalRoutes.setState({ value: routes });
|
|
8
|
+
const active = routes.find(r => isRouteMatching(r.pathname)) || { pathname: window.location.href, component: Page404 };
|
|
9
|
+
const { pathname: currentpath, href } = window.location;
|
|
10
|
+
const params = extractParamsFromURL(currentpath, active.pathname);
|
|
11
|
+
const queryParams = extractQueryParamsFromURL(href);
|
|
12
|
+
activeRoute.setState({ value: active });
|
|
13
|
+
location.setState({ value: { params, queryParams, ...window.location } });
|
|
4
14
|
return routes;
|
|
5
15
|
};
|
|
6
16
|
export default createRoutes;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const isRouteMatching = (routePath) => {
|
|
5
5
|
const current = window.location.pathname;
|
|
6
|
-
if (routePath === "/") {
|
|
7
|
-
return current === "/";
|
|
6
|
+
if (routePath === "/" || routePath === "") {
|
|
7
|
+
return current === "/" || current === "/index.html" || current === "";
|
|
8
8
|
}
|
|
9
9
|
const routeParts = routePath.split("/").filter(Boolean);
|
|
10
10
|
const currentParts = current.split("/").filter(Boolean);
|
package/package.json
CHANGED