fix: redirect default path after login
This commit is contained in:
+12
-17
@@ -96,15 +96,6 @@ export default (props: any) => {
|
||||
|
||||
const formatMessage = undefined;
|
||||
|
||||
// const runtimeConfig = pluginManager.applyPlugins({
|
||||
// key: 'layout',
|
||||
// type: 'modify',
|
||||
// logout: true,
|
||||
// initialValue: {
|
||||
// ...initialInfo,
|
||||
// notFound: <div>not found</div>
|
||||
// }
|
||||
// });
|
||||
const runtimeConfig = {
|
||||
...initialInfo,
|
||||
logout: async (userInfo) => {
|
||||
@@ -114,12 +105,6 @@ export default (props: any) => {
|
||||
},
|
||||
notFound: <span>404 not found</span>
|
||||
};
|
||||
console.log('clientRoute==========2=', {
|
||||
props,
|
||||
clientRoutes,
|
||||
runtimeConfig,
|
||||
initialInfo
|
||||
});
|
||||
|
||||
// 现在的 layout 及 wrapper 实现是通过父路由的形式实现的, 会导致路由数据多了冗余层级, proLayout 消费时, 无法正确展示菜单, 这里对冗余数据进行过滤操作
|
||||
const newRoutes = filterRoutes(
|
||||
@@ -131,15 +116,20 @@ export default (props: any) => {
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
console.log('clientRoutes===========', clientRoutes, newRoutes);
|
||||
const [route] = useAccessMarkedRoutes(mapRoutes(newRoutes));
|
||||
patchRoutes({ routes: route?.children || [] });
|
||||
|
||||
patchRoutes({
|
||||
routes: route.children,
|
||||
initialState: initialInfo.initialState
|
||||
});
|
||||
|
||||
const matchedRoute = useMemo(
|
||||
() => matchRoutes(route?.children || [], location.pathname)?.pop?.()?.route,
|
||||
[location.pathname]
|
||||
);
|
||||
console.log('route===========', route);
|
||||
console.log('route===========', matchedRoute, route);
|
||||
return (
|
||||
<div>
|
||||
<div className="background"></div>
|
||||
@@ -160,6 +150,11 @@ export default (props: any) => {
|
||||
// 如果没有登录,重定向到 login
|
||||
if (!initialState?.currentUser && location.pathname !== loginPath) {
|
||||
history.push(loginPath);
|
||||
} else if (location.path === '/') {
|
||||
const pathname = initialState?.currentUser?.is_admin
|
||||
? '/dashboard'
|
||||
: '/playground';
|
||||
history.push(pathname);
|
||||
}
|
||||
}}
|
||||
formatMessage={userConfig.formatMessage || formatMessage}
|
||||
|
||||
+13
-10
@@ -7,30 +7,33 @@ import icons from './icons';
|
||||
function formatIcon(name: string) {
|
||||
return name
|
||||
.replace(name[0], name[0].toUpperCase())
|
||||
.replace(/-(w)/g, function(all, letter) {
|
||||
.replace(/-(w)/g, function (all, letter) {
|
||||
return letter.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
export function patchRoutes({ routes }) {
|
||||
console.log('patchRoutes====',routes)
|
||||
Object.keys(routes).forEach(key => {
|
||||
export function patchRoutes({ routes, initialState }) {
|
||||
console.log('patchRoutes99999', routes);
|
||||
Object.keys(routes).forEach((key) => {
|
||||
const { icon } = routes[key];
|
||||
if (icon && typeof icon === 'string') {
|
||||
const upperIcon = formatIcon(icon);
|
||||
if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
|
||||
routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
|
||||
routes[key].icon = React.createElement(
|
||||
icons[upperIcon] || icons[upperIcon + 'Outlined']
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function renderMenuIcon (icon: string){
|
||||
|
||||
export function renderMenuIcon(icon: string) {
|
||||
const upperIcon = formatIcon(icon);
|
||||
console.log('upperIcon',upperIcon)
|
||||
console.log('upperIcon', upperIcon);
|
||||
if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
|
||||
return React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
|
||||
return React.createElement(
|
||||
icons[upperIcon] || icons[upperIcon + 'Outlined']
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user