@@ -4,15 +4,16 @@ import type { DId } from '@react-devui/ui/utils/types';
4
4
import type { IndexRouteObject , NonIndexRouteObject , RouteMatch } from 'react-router-dom' ;
5
5
6
6
import { isUndefined , nth } from 'lodash' ;
7
- import React , { useEffect } from 'react' ;
7
+ import React from 'react' ;
8
8
import { useTranslation } from 'react-i18next' ;
9
9
import { matchRoutes , Navigate , renderMatches , useLocation } from 'react-router-dom' ;
10
10
11
11
import { ROUTES_ACL } from '../config/acl' ;
12
- import { LOGIN_PATH , TITLE_CONFIG } from '../config/other' ;
13
- import { useMenu } from '../core' ;
12
+ import { LOGIN_PATH } from '../config/other' ;
14
13
import { useACLGuard , useTokenGuard } from './Routes.guard' ;
15
14
import { AppFCPLoader } from './components' ;
15
+ import { usePageTitle } from './hooks' ;
16
+ import AppHomeRoute from './routes/Home' ;
16
17
import AppExceptionRoute from './routes/exception/Exception' ;
17
18
import AppLayout from './routes/layout/Layout' ;
18
19
import AppLoginRoute from './routes/login/Login' ;
@@ -62,7 +63,6 @@ export function AppRoutes() {
62
63
const ACLGuard = useACLGuard ( ) ;
63
64
const tokenGuard = useTokenGuard ( ) ;
64
65
const location = useLocation ( ) ;
65
- const [ , allItem ] = useMenu ( ) ;
66
66
const { t } = useTranslation ( ) ;
67
67
68
68
const matches = matchRoutes (
@@ -83,19 +83,12 @@ export function AppRoutes() {
83
83
} ,
84
84
children : [
85
85
{
86
- index : true ,
87
- element : '/' ,
86
+ path : '' ,
87
+ element : < AppHomeRoute /> ,
88
88
} ,
89
89
{
90
90
path : 'dashboard' ,
91
- data : {
92
- titleI18n : 'dashboard.' ,
93
- } ,
94
91
children : [
95
- {
96
- index : true ,
97
- element : '/dashboard' ,
98
- } ,
99
92
{
100
93
path : 'amap' ,
101
94
element : (
@@ -126,14 +119,7 @@ export function AppRoutes() {
126
119
} ,
127
120
{
128
121
path : 'test' ,
129
- data : {
130
- titleI18n : 'test.' ,
131
- } ,
132
122
children : [
133
- {
134
- index : true ,
135
- element : '/test' ,
136
- } ,
137
123
{
138
124
path : 'acl' ,
139
125
element : (
@@ -165,37 +151,8 @@ export function AppRoutes() {
165
151
] ,
166
152
} ,
167
153
{
168
- path : 'exception' ,
169
- data : {
170
- titleI18n : 'exception.' ,
171
- } ,
172
- children : [
173
- {
174
- index : true ,
175
- element : '/exception' ,
176
- } ,
177
- {
178
- path : '403' ,
179
- element : < AppExceptionRoute status = { 403 } /> ,
180
- data : {
181
- titleI18n : 'exception.403' ,
182
- } ,
183
- } ,
184
- {
185
- path : '404' ,
186
- element : < AppExceptionRoute status = { 404 } /> ,
187
- data : {
188
- titleI18n : 'exception.404' ,
189
- } ,
190
- } ,
191
- {
192
- path : '500' ,
193
- element : < AppExceptionRoute status = { 500 } /> ,
194
- data : {
195
- titleI18n : 'exception.500' ,
196
- } ,
197
- } ,
198
- ] ,
154
+ path : 'exception/:status' ,
155
+ element : < AppExceptionRoute /> ,
199
156
} ,
200
157
{
201
158
path : '*' ,
@@ -226,30 +183,12 @@ export function AppRoutes() {
226
183
}
227
184
}
228
185
229
- const currentRoute = matches [ matches . length - 1 ] . route ;
230
- if ( currentRoute . index === true ) {
231
- const firstMenu = allItem . find ( ( item ) => item . id . startsWith ( currentRoute . element as string ) ) ;
232
- return < Navigate to = { isUndefined ( firstMenu ) ? '/exception/404' : firstMenu . id } replace /> ;
233
- }
234
186
return renderMatches ( matches ) ;
235
187
} ) ( ) ;
236
188
237
- useEffect ( ( ) => {
238
- const { title : _title , titleI18n } = nth ( matches , - 1 ) ?. route . data ?? { } ;
239
- const title = _title ?? ( isUndefined ( titleI18n ) ? undefined : t ( titleI18n , { ns : 'title' } ) ) ;
240
- if ( isUndefined ( title ) ) {
241
- document . title = TITLE_CONFIG . default ;
242
- } else {
243
- const arr = [ title ] ;
244
- if ( TITLE_CONFIG . prefix ) {
245
- arr . unshift ( TITLE_CONFIG . prefix ) ;
246
- }
247
- if ( TITLE_CONFIG . suffix ) {
248
- arr . push ( TITLE_CONFIG . suffix ) ;
249
- }
250
- document . title = arr . join ( TITLE_CONFIG . separator ?? ' - ' ) ;
251
- }
252
- } ) ;
189
+ const { title : _title , titleI18n } = nth ( matches , - 1 ) ?. route . data ?? { } ;
190
+ const title = _title ?? ( isUndefined ( titleI18n ) ? undefined : t ( titleI18n , { ns : 'title' } ) ) ;
191
+ usePageTitle ( title ) ;
253
192
254
193
return (
255
194
< RouteStateContext . Provider
0 commit comments