preact-hashish-router 0.0.12 → 0.0.14
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 +20 -0
- package/dist/Redirect.d.ts +4 -0
- package/dist/Redirect.js +10 -0
- package/dist/Router.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,26 @@ export default function Header() {
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
### `<Redirect />` Component
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { Redirect } from "preact-hashish-router";
|
|
95
|
+
|
|
96
|
+
export default function ProductPage() {
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<header>
|
|
100
|
+
<nav>
|
|
101
|
+
<A href="/">Home</A>
|
|
102
|
+
<A href="/about">About</A>
|
|
103
|
+
</nav>
|
|
104
|
+
</header>
|
|
105
|
+
<Redirect to="/" />
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
91
111
|
## Development
|
|
92
112
|
|
|
93
113
|
If you have any improvements or find any issues, feel free to contribute or open an issue in the associated repository.
|
package/dist/Redirect.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { Fragment, useLayoutEffect } from "preact/compat";
|
|
3
|
+
import { useRouter } from "./useRouter";
|
|
4
|
+
export const Redirect = (props) => {
|
|
5
|
+
const router = useRouter();
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
router.go(props.to);
|
|
8
|
+
}, []);
|
|
9
|
+
return _jsx(Fragment, {});
|
|
10
|
+
};
|
package/dist/Router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useLayoutEffect, 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) => {
|
|
@@ -38,7 +38,7 @@ export const Router = (props) => {
|
|
|
38
38
|
window.removeEventListener("hashchange", browserEffectHandler.listener);
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
42
|
if (router_type !== "hash")
|
|
43
43
|
return;
|
|
44
44
|
const [path, query] = get_hash_route().split("?");
|
|
@@ -53,7 +53,7 @@ export const Router = (props) => {
|
|
|
53
53
|
hashEffectHandler.effect();
|
|
54
54
|
return () => hashEffectHandler.cleanUp();
|
|
55
55
|
}, []);
|
|
56
|
-
|
|
56
|
+
useLayoutEffect(() => {
|
|
57
57
|
if (router_type !== "browser")
|
|
58
58
|
return;
|
|
59
59
|
setPath(location.pathname);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED