1
- import { useEffect } from "react" ;
2
- import { match , matchPath , useLocation } from "react-router" ;
3
- import { RouteConfig } from "react-router-config" ;
4
- import { Location } from "history" ;
1
+ import { useEffect } from 'react' ;
2
+ import { PathMatch , matchPath , useLocation , RouteObject } from 'react-router' ;
3
+ import { Location } from 'history' ;
5
4
6
5
export interface TitleObject {
7
6
title : string ;
8
7
titles : string [ ] ;
9
- params : match [ " params" ] ;
8
+ params : PathMatch [ ' params' ] ;
10
9
}
11
10
12
11
type Routes = RouteConfigExtended [ ] | {
13
12
[ name : string ] : RouteConfigExtended ,
14
13
} ;
15
14
16
- export interface RouteConfigExtended extends Omit < RouteConfig , "routes" > {
15
+ export interface RouteConfigExtended extends Omit < RouteObject , 'children' > {
17
16
title : string ;
18
17
titleConcat ?: boolean ;
19
- routes ?: Routes ;
18
+ children ?: Routes ;
19
+ path : string ;
20
20
}
21
21
22
- const getRoute = ( routesConfig : Routes , path : string ) : { route : RouteConfigExtended , currentMatch : match } => {
22
+ const getRoute = ( routesConfig : Routes , path : string ) : { route : RouteConfigExtended , currentMatch : PathMatch } => {
23
23
let route : RouteConfigExtended ;
24
- let currentMatch : match ;
24
+ let currentMatch : PathMatch ;
25
25
26
26
if ( Array . isArray ( routesConfig ) ) {
27
27
route = routesConfig . find ( ( routeConfig ) => {
28
- currentMatch = matchPath ( path , routeConfig as RouteConfig ) ;
28
+ currentMatch = matchPath ( routeConfig , path ) ;
29
29
return currentMatch ;
30
30
} ) ;
31
31
} else {
32
32
const id : string = Object . keys ( routesConfig ) . find ( ( key ) => {
33
- currentMatch = matchPath ( path , routesConfig [ key ] as RouteConfig ) ;
33
+ currentMatch = matchPath ( routesConfig [ key ] , path ) ;
34
34
return currentMatch ;
35
35
} ) ;
36
36
route = routesConfig [ id ] ;
@@ -47,7 +47,7 @@ const getTitle = (
47
47
path : string ,
48
48
divider : string ,
49
49
titles : string [ ] = [ ] ,
50
- matchCache ?: match ,
50
+ matchCache ?: PathMatch ,
51
51
) : TitleObject => {
52
52
const { route, currentMatch } = getRoute ( routesConfig , path ) ;
53
53
@@ -56,8 +56,8 @@ const getTitle = (
56
56
if ( route && concatenateTitles ) {
57
57
if ( route . title ) { titles . push ( route . title ) ; }
58
58
59
- if ( route . routes ) {
60
- return getTitle ( route . routes , path , divider , titles , currentMatch || matchCache ) ;
59
+ if ( route . children ) {
60
+ return getTitle ( route . children , path , divider , titles , currentMatch || matchCache ) ;
61
61
}
62
62
}
63
63
@@ -80,7 +80,7 @@ const RouterTitle = ({
80
80
pageTitle,
81
81
routesConfig,
82
82
callback = ( { title } ) => title ,
83
- divider = "·" ,
83
+ divider = '·' ,
84
84
prefix,
85
85
} : RouterTitleProps ) => {
86
86
const location = useLocation ( ) ;
0 commit comments