preact-hashish-router 0.0.11 → 0.0.13
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.d.ts +9 -0
- package/dist/Router.js +5 -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.d.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { PropsWithChildren } from "preact/compat";
|
|
|
2
2
|
import { RouterContext } from "./context";
|
|
3
3
|
type RouterProps = PropsWithChildren & {
|
|
4
4
|
type: RouterContext["type"];
|
|
5
|
+
/**
|
|
6
|
+
* Only for `hash` routers.
|
|
7
|
+
*
|
|
8
|
+
* Decide if the initial pathname will be rewrite as the initial hash.
|
|
9
|
+
*
|
|
10
|
+
* `Caution`: This will replace the initial url hash
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
redirect_path_to_hash?: boolean;
|
|
5
14
|
};
|
|
6
15
|
export declare const Router: (props: RouterProps) => import("preact").JSX.Element;
|
|
7
16
|
export {};
|
package/dist/Router.js
CHANGED
|
@@ -44,9 +44,11 @@ export const Router = (props) => {
|
|
|
44
44
|
const [path, query] = get_hash_route().split("?");
|
|
45
45
|
setQuery(query || "");
|
|
46
46
|
setPath(path);
|
|
47
|
-
if (
|
|
48
|
-
location.
|
|
49
|
-
|
|
47
|
+
if (props.redirect_path_to_hash === true) {
|
|
48
|
+
if (location.pathname !== "/") {
|
|
49
|
+
location.hash = location.pathname;
|
|
50
|
+
location.pathname = "";
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
hashEffectHandler.effect();
|
|
52
54
|
return () => hashEffectHandler.cleanUp();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED