crossroad 3.0.10 → 3.0.11
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 +11 -13
- package/readme.md +11 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crossroad",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"description": "A React library to handle navigation easily in your WebApp",
|
|
5
5
|
"homepage": "https://crossroad.page/",
|
|
6
6
|
"repository": "github:franciscop/crossroad",
|
|
@@ -14,15 +14,6 @@
|
|
|
14
14
|
"javascript",
|
|
15
15
|
"hooks"
|
|
16
16
|
],
|
|
17
|
-
"documentation": {
|
|
18
|
-
"home": "assets/home.html",
|
|
19
|
-
"menu": {
|
|
20
|
-
"Documentation": "/documentation",
|
|
21
|
-
"Donate": "https://www.paypal.me/franciscopresencia/19",
|
|
22
|
-
"Author": "https://francisco.io/",
|
|
23
|
-
"Github": "https://github.com/franciscop/crossroad"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
17
|
"scripts": {
|
|
27
18
|
"build": "npm run build:library && npm run build:types && npm run build:prettier",
|
|
28
19
|
"build:library": "vite build && mv dist/index.min.js . && rm -rf dist",
|
|
@@ -37,7 +28,6 @@
|
|
|
37
28
|
"type": "module",
|
|
38
29
|
"types": "index.d.ts",
|
|
39
30
|
"files": [
|
|
40
|
-
"index.min.js",
|
|
41
31
|
"index.d.ts"
|
|
42
32
|
],
|
|
43
33
|
"devDependencies": {
|
|
@@ -51,14 +41,22 @@
|
|
|
51
41
|
"prettier": "^3.8.1",
|
|
52
42
|
"react": "^18.3.1",
|
|
53
43
|
"react-dom": "^18.3.1",
|
|
54
|
-
"react-test": "^0.24.
|
|
44
|
+
"react-test": "^0.24.3",
|
|
55
45
|
"terser": "^5.46.1",
|
|
56
46
|
"typescript": "^6.0.2",
|
|
57
47
|
"vite": "^8.0.3",
|
|
58
|
-
"vite-plugin-dts": "^4.5.4",
|
|
59
48
|
"vitest": "^4.1.2"
|
|
60
49
|
},
|
|
61
50
|
"peerDependencies": {
|
|
62
51
|
"react": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"documentation": {
|
|
54
|
+
"home": "assets/home.html",
|
|
55
|
+
"menu": {
|
|
56
|
+
"Documentation": "/documentation",
|
|
57
|
+
"Donate": "https://www.paypal.me/franciscopresencia/19",
|
|
58
|
+
"Author": "https://francisco.io/",
|
|
59
|
+
"Github": "https://github.com/franciscop/crossroad"
|
|
60
|
+
}
|
|
63
61
|
}
|
|
64
62
|
}
|
package/readme.md
CHANGED
|
@@ -6,7 +6,7 @@ A React library to handle navigation in your WebApp. Built with simple component
|
|
|
6
6
|
- Very useful hooks like [`useUrl`](#useurl), [`useQuery`](#usequery), etc. Follow [the rules of hooks](https://reactjs.org/docs/hooks-rules.html).
|
|
7
7
|
- Links are plain `<a>` instead of custom components. [Read more](#a).
|
|
8
8
|
- The `<Route>` path is `exact` by default and can match query parameters.
|
|
9
|
-
- It's [just ~1.
|
|
9
|
+
- It's [just ~1.9kb](https://bundlephobia.com/package/crossroad) (min+gzip) instead of the 17kb of React Router(+Dom).
|
|
10
10
|
- Add `scrollUp` to `<Router>` o `<Route>` to automatically scroll up on a route change.
|
|
11
11
|
|
|
12
12
|
[**🔗 Demo on CodeSandbox**](https://codesandbox.io/s/recursing-wozniak-uftyo?file=/src/App.js)
|
|
@@ -250,7 +250,8 @@ const UserList = () => <div>List here</div>;
|
|
|
250
250
|
// <div>List here</div>
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
>
|
|
253
|
+
> [!WARNING]
|
|
254
|
+
> The parameter is passed straight to the component instead of wrapped like in React Router, see the examples above.
|
|
254
255
|
|
|
255
256
|
The path can also include a wildcard `*`, in which case it will perform a partial match of everything before itself. It can only be at the end of the path:
|
|
256
257
|
|
|
@@ -265,7 +266,9 @@ The path can also include a wildcard `*`, in which case it will perform a partia
|
|
|
265
266
|
<Route path="/user/:id/*" component={User} />
|
|
266
267
|
```
|
|
267
268
|
|
|
268
|
-
|
|
269
|
+
|
|
270
|
+
> [!TIP]
|
|
271
|
+
> In Crossroad the paths are exact by default, and with the wildcard you can make them partial matches. So the wildcard is the opposite of adding `exact` to React Router.
|
|
269
272
|
|
|
270
273
|
It can also match query parameters:
|
|
271
274
|
|
|
@@ -347,9 +350,7 @@ Some examples:
|
|
|
347
350
|
|
|
348
351
|
### `useUrl()`
|
|
349
352
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
Read and set the full URL:
|
|
353
|
+
Read and set the full URL (path + search query + hash):
|
|
353
354
|
|
|
354
355
|
```js
|
|
355
356
|
import { useUrl } from "crossroad";
|
|
@@ -485,7 +486,7 @@ const Login = () => {
|
|
|
485
486
|
|
|
486
487
|
The path is always a string equivalent to `window.location.pathname`. Why not use `window.location.pathname` then? Because usePath() is a hook that will trigger a re-render when the path changes!
|
|
487
488
|
|
|
488
|
-
|
|
489
|
+
`setPath` _only_ modifies the path(name) and keeps the search query and hash the same, so if you want to modify the full URL you should instead utilize `useUrl()` and `setUrl('/welcome')`
|
|
489
490
|
|
|
490
491
|
#### Setter
|
|
491
492
|
|
|
@@ -496,7 +497,7 @@ setPath("/newpath");
|
|
|
496
497
|
setPath((oldPath) => "/newpath");
|
|
497
498
|
```
|
|
498
499
|
|
|
499
|
-
The function `setPath` is _always_
|
|
500
|
+
The function `setPath` is _always_ stable, so it doesn't matter whether you put it as a dependency or not. However the `path` can be updated, so you might want to put that:
|
|
500
501
|
|
|
501
502
|
```js
|
|
502
503
|
const [path, setPath] = usePath();
|
|
@@ -922,7 +923,8 @@ In this case the order matters, because the generic NotFound will be matched wit
|
|
|
922
923
|
|
|
923
924
|
### Github hosting
|
|
924
925
|
|
|
925
|
-
>
|
|
926
|
+
> [!WARNING]
|
|
927
|
+
> This is a bad idea for SEO, but if that doesn't matter much for you go ahead and host your webapp in Github Pages
|
|
926
928
|
|
|
927
929
|
Github pages is a bit particular in that as of this writing it does not allow for a generic redirect like most other static website servers, so we need to do a workaround with the `404.html` page.
|
|
928
930
|
|