Skip to content

Commit b79947f

Browse files
authored
Feature: add subrouting + update routing types (#13)
* . * . * . * .
1 parent 5b8a11b commit b79947f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
## [Unreleased]
99

1010
### Added
11+
- [MINOR] Added `useLocation`
12+
- [MINOR] Added `SubRouteOutlet` to render sub-routes within a route
1113

1214
### Changed
15+
- [MINOR] Fixes for routing types
1316

1417
### Removed
1518

src/routing.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22

3-
import { Route as ReactRoute, Routes, useNavigate, useParams as useRouterParams } from 'react-router';
3+
import { Location } from 'history';
4+
import { Outlet, Route as ReactRoute, Routes, useNavigate, useLocation as useReactLocation, useParams as useRouterParams } from 'react-router';
45
import { BrowserRouter, Link as ReactLink } from 'react-router-dom';
56
import { StaticRouter } from 'react-router-dom/server';
67

@@ -21,6 +22,11 @@ export const useNavigator = (): Navigator => {
2122
};
2223
};
2324

25+
export const useLocation = (): Location => {
26+
const reactLocation = useReactLocation();
27+
return reactLocation;
28+
};
29+
2430
export interface IRouterAuthManager {
2531
getIsUserLoggedIn: () => boolean;
2632
}
@@ -32,7 +38,7 @@ export const useRouterAuthManager = (): IRouterAuthManager | undefined => {
3238
return authManager;
3339
};
3440

35-
export interface IRouteProps<PagePropsType = Record<string, unknown>> {
41+
export interface IRouteProps<PagePropsType = Record<string, string>> extends IMultiChildProps<IRouteProps> {
3642
path?: string;
3743
default?: boolean;
3844
redirectIfAuth?: string;
@@ -94,6 +100,16 @@ export const SubRouter = (props: ISubRouterProps): React.ReactElement => {
94100
);
95101
};
96102

103+
export interface ISubRouterOutletProps {
104+
}
105+
106+
// eslint-disable-next-line unused-imports/no-unused-vars
107+
export const SubRouterOutlet = (props: ISubRouterOutletProps): React.ReactElement => {
108+
return (
109+
<Outlet />
110+
);
111+
};
112+
97113
export interface IRouterProps extends ISubRouterProps {
98114
authManager?: IRouterAuthManager;
99115
staticPath?: string;
@@ -102,7 +118,7 @@ export interface IRouterProps extends ISubRouterProps {
102118
export const Router = (props: IRouterProps): React.ReactElement => {
103119
const internals = (
104120
<RouterAuthManagerContext.Provider value={props.authManager}>
105-
<SubRouter {...props}>
121+
<SubRouter>
106122
{ props.children }
107123
</SubRouter>
108124
</RouterAuthManagerContext.Provider>

0 commit comments

Comments
 (0)