From 5e02d635efa17d57eeb338438f6b1a85f4f0b8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Wed, 27 Dec 2017 12:10:37 +0800 Subject: [PATCH] fix list redirect bug (#507) --- src/common/menu.js | 25 +++++++++++----------- src/layouts/BasicLayout.js | 43 +++++++++++++++++++++++++++++--------- src/routes/List/List.js | 3 +-- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/common/menu.js b/src/common/menu.js index cf9a4e72..109856a9 100644 --- a/src/common/menu.js +++ b/src/common/menu.js @@ -32,28 +32,27 @@ const menuData = [{ icon: 'table', path: 'list', children: [{ + name: '查询表格', + path: 'table-list', + }, { + name: '标准列表', + path: 'basic-list', + }, { + name: '卡片列表', + path: 'card-list', + }, { name: '搜索列表', - icon: 'search', path: 'search', children: [{ + name: '搜索列表(文章)', + path: 'articles', + }, { name: '搜索列表(项目)', path: 'projects', }, { name: '搜索列表(应用)', path: 'applications', - }, { - name: '搜索列表(文章)', - path: 'articles', }], - }, { - name: '查询表格', - path: 'table-list', - }, { - name: '标准列表', - path: 'basic-list', - }, { - name: '卡片列表', - path: 'card-list', }], }, { name: '详情页', diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index a5380d28..3593b4d5 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -11,9 +11,29 @@ import GlobalFooter from '../components/GlobalFooter'; import SiderMenu from '../components/SiderMenu'; import NotFound from '../routes/Exception/404'; import { getRoutes } from '../utils/utils'; +import { getMenuData } from '../common/menu'; -const { Content } = Layout; +/** + * 根据菜单取得重定向地址. + */ +const redirectData = []; +const getRedirect = (item) => { + if (item && item.children) { + if (item.children[0] && item.children[0].path) { + redirectData.push({ + from: `/${item.path}`, + to: `/${item.children[0].path}`, + }); + item.children.forEach((children) => { + getRedirect(children); + }); + } + } +}; +getMenuData().forEach(getRedirect); + +const { Content } = Layout; const query = { 'screen-xs': { maxWidth: 575, @@ -79,17 +99,20 @@ class BasicLayout extends React.PureComponent {
{ - getRoutes(match.path, routerData).map(item => - ( - - ) + redirectData.map(item => + ) } + { + getRoutes(match.path, routerData).map(item => ( + + )) + } diff --git a/src/routes/List/List.js b/src/routes/List/List.js index e7b10a69..0d039194 100644 --- a/src/routes/List/List.js +++ b/src/routes/List/List.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { routerRedux, Route, Switch, Redirect } from 'dva/router'; +import { routerRedux, Route, Switch } from 'dva/router'; import { connect } from 'dva'; import { Input } from 'antd'; import PageHeaderLayout from '../../layouts/PageHeaderLayout'; @@ -72,7 +72,6 @@ export default class SearchList extends Component { ) ) } - ); -- GitLab