Skip to content

Commit 1068f1b

Browse files
committedMay 1, 2024
fix #408 - accessing route information
1 parent e94f8ef commit 1068f1b

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed
 

‎.changeset/strong-ducks-fold.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
fix #408 - accessing route information

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ It supports all of Solid's SSR methods and has Solid's transitions baked in, so
3030
- [useSearchParams](#usesearchparams)
3131
- [useIsRouting](#useisrouting)
3232
- [useMatch](#usematch)
33+
- [useCurrentMatches](#useCurrentMatches)
3334
- [useBeforeLeave](#usebeforeleave)
3435
- [SPAs in Deployed Environments](#spas-in-deployed-environments)
3536

@@ -860,6 +861,16 @@ const match = useMatch(() => props.href);
860861
return <div classList={{ active: Boolean(match()) }} />;
861862
```
862863

864+
### useCurrentMatches
865+
866+
`useCurrentMatches` returns all the matches for the current matched route. Useful for getting all the route information.
867+
868+
For example if you stored breadcrumbs on your route definition you could retrieve them like so:
869+
```js
870+
const matches = useCurrentMatches();
871+
const breadcrumbs = createMemo(() => matches.map(m => m.route.info.breadcrumb))
872+
```
873+
863874
### useBeforeLeave
864875

865876
`useBeforeLeave` takes a function that will be called prior to leaving a route. The function will be called with:

‎src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {
66
useIsRouting,
77
useLocation,
88
useMatch,
9+
useCurrentMatches,
910
useNavigate,
1011
useParams,
1112
useResolvedPath,

‎src/routing.ts

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export const useMatch = <S extends string>(path: () => S, matchFilters?: MatchFi
9191
});
9292
};
9393

94+
export const useCurrentMatches = () => useRouter().matches();
95+
9496
export const useParams = <T extends Params>() => useRouter().params as T;
9597

9698
export const useSearchParams = <T extends Params>(): [

0 commit comments

Comments
 (0)
Please sign in to comment.