preact-hashish-router 0.0.8 → 0.0.9
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/dist/Router.js +9 -5
- package/package.json +4 -2
package/dist/Router.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useEffect, useMemo, useState } from "preact/hooks";
|
|
|
3
3
|
import { router_context } from "./context";
|
|
4
4
|
const get_hash_route = () => location.hash.slice(1) || "/";
|
|
5
5
|
export const Router = (props) => {
|
|
6
|
-
const [path, setPath] = useState(
|
|
6
|
+
const [path, setPath] = useState();
|
|
7
7
|
const [query, setQuery] = useState("");
|
|
8
8
|
const [itMatch, setItMatch] = useState(false);
|
|
9
9
|
const router_type = useMemo(() => {
|
|
@@ -44,6 +44,10 @@ export const Router = (props) => {
|
|
|
44
44
|
const [path, query] = get_hash_route().split("?");
|
|
45
45
|
setQuery(query || "");
|
|
46
46
|
setPath(path);
|
|
47
|
+
if (location.pathname !== "/") {
|
|
48
|
+
location.hash = location.pathname;
|
|
49
|
+
location.pathname = "";
|
|
50
|
+
}
|
|
47
51
|
hashEffectHandler.effect();
|
|
48
52
|
return () => hashEffectHandler.cleanUp();
|
|
49
53
|
}, []);
|
|
@@ -55,15 +59,15 @@ export const Router = (props) => {
|
|
|
55
59
|
browserEffectHandler.effect();
|
|
56
60
|
return () => browserEffectHandler.cleanUp();
|
|
57
61
|
}, []);
|
|
58
|
-
const handlerManualRouteChange = (
|
|
59
|
-
setPath(
|
|
62
|
+
const handlerManualRouteChange = (newPath) => {
|
|
63
|
+
setPath(newPath);
|
|
60
64
|
setItMatch(false);
|
|
61
65
|
if (router_type === "hash") {
|
|
62
|
-
location.hash =
|
|
66
|
+
location.hash = newPath;
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
65
69
|
if (router_type === "browser") {
|
|
66
|
-
history.pushState(null, "", new URL(
|
|
70
|
+
history.pushState(null, "", new URL(newPath, location.origin));
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
69
73
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-hashish-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"description": "A simple router for preact",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc -p ./tsconfig.json",
|
|
8
|
+
"build": "tsc -p ./tsconfig.lib.json",
|
|
9
9
|
"format": "prettier --write src --ignore-unknown",
|
|
10
|
+
"app:dev": "vite",
|
|
10
11
|
"prepublishOnly": "npm run build && npm run format",
|
|
11
12
|
"push": "npm version patch && git push",
|
|
12
13
|
"push-minor": "npm version minor && git push",
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
"author": "LiasCode",
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@preact/preset-vite": "^2.10.1",
|
|
34
|
+
"@types/node": "^22.13.4",
|
|
33
35
|
"preact-hashish-router": "^0.0.6",
|
|
34
36
|
"prettier": "^3.5.1",
|
|
35
37
|
"prettier-plugin-organize-imports": "^4.1.0",
|