Skip to content

Commit c0c98c2

Browse files
fix: typescript compiler for dynamic routing solution (#51)
adds breadcrumb to the Route type from react router
1 parent a5a3188 commit c0c98c2

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Pathname | Result
140140
Same as the example above using Declarative Routing.
141141
142142
```js
143-
import useBreadcrumbs, { createRoutesFromChildren } from 'use-react-router-breadcrumbs';
143+
import useBreadcrumbs, { createRoutesFromChildren, Route } from 'use-react-router-breadcrumbs';
144144
145145
const userNamesById = { '1': 'John' }
146146

src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from 'react';
44
import PropTypes from 'prop-types';
55
import { mount } from 'enzyme';
6-
import { MemoryRouter as Router, Route, Routes } from 'react-router';
6+
import { MemoryRouter as Router, Route } from 'react-router';
77
import useBreadcrumbs, { getBreadcrumbs, createRoutesFromChildren } from './index.tsx';
88

99
// imports to test compiled builds

src/index.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {
2525
Params,
2626
PathPattern,
2727
Route,
28+
PathRouteProps,
29+
LayoutRouteProps,
30+
IndexRouteProps,
2831
} from 'react-router';
2932

3033
type Location = ReturnType<typeof useLocation>;
@@ -512,3 +515,13 @@ export function createRoutesFromChildren(
512515

513516
return routes;
514517
}
518+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
519+
type BreadCrumb = { breadcrumb?: string | ((param: any) => JSX.Element) | JSX.Element | null };
520+
521+
type BreadCrumbRouteType = (
522+
_props: PathRouteProps | LayoutRouteProps | IndexRouteProps & BreadCrumb
523+
) => React.ReactElement | null;
524+
525+
const BreadCrumbRoute: BreadCrumbRouteType = Route;
526+
527+
export { BreadCrumbRoute as Route };

0 commit comments

Comments
 (0)