Comments (6)
就是这个思路
from react-antd-admin.
在 index.js
里定义新的页面路由,具体可以看 react-router
的文档
接着换掉左侧菜单的链接为你新定义的路由地址
from react-antd-admin.
@fireyy 我现在说一下我的理解,大神看下对不对。
1.在index.js中添加新路由:比如这样:
<Provider store={store}> <Router history={history}> <Route path="/" onEnter={validate}> <IndexRedirect to="home" /> <Route component={App}> <Route path="home" component={Home}/> **<Route path="menu301" component={Menu301} />** </Route> <Route path="login" component={Login}/> </Route> </Router> </Provider>
其中,<Route path="menu301" component={Menu301} />
是我添加的路由信息。
2.在sidebar的index.js文件中添加上面的链接,如下:
render () { const { items } = this.props let openKey = [] const menu = items.map((item) => { openKey.push('sub'+item.key) return ( <SubMenu key={'sub'+item.key} title={<span><Icon type={item.icon} />{item.name}</span>} > {item.child.map((node) => { return ( <Menu.Item key={'menu'+node.key}> **<Link to={'menu'+node.key}>{node.name} </Link>** </Menu.Item> ) })} </SubMenu> ) }); return ( <aside className="ant-layout-sider"> <Menu mode="inline" theme="light" openKeys={openKey} onClick={this.menuClickHandle} style={{borderRight: 0}} > {menu} </Menu> </aside> ) }
其中,<Link to={'menu'+node.key}>{node.name}</Link>
是我添加的,以前是没有这个Link的。
这样,确实可以实现页面的跳转,主要依靠的是Link组件。
现在我想请教大神,这样实现有问题么?如果有问题的话,有没有更好的实现方法呢?谢谢!
可能代码格式有点混乱,不知道这个编辑器怎么换行,大神先凑合看下。
from react-antd-admin.
非常感谢!还有个问题,一会我再开个issue吧。
from react-antd-admin.
我也是初学者,准备定制这个手脚架。
基于现在最新的代码,关于左侧sideBar和路由部分我不太明白,从代码看,现在的路由是在src/api/mock
中指定的,而我尝试修改src/route/index.js
中的路由配置部分(只加了TestPage2):
const routes = (
<Route path="/" onEnter={validate}>
<IndexRedirect to="home" />
<Route component={App}>
<Route path="home" component={Home}/>
<Route path="form" component={Form}/>
<Route path="table" component={Table}/>
<Route path="page2" component={Page2}/>
<Route path="TestPage2" component={Page2}/>
</Route>
<Route path="login" component={Login}/>
</Route>
);
发现前端没有变化,希望请教下如何取消使用mock中的路由数据,而直接用src/route
中的路由配置?
from react-antd-admin.
@adolphlwq 这两者不一样,src/api/mock
里的数据代表模拟服务端下发的 menu 数据,用于页面显示,而 src/route
里代表的是这个应用支持的所有路由配置,所以新增一个页面的顺序是:
- 在
src/route
里配置新<Route />
- 如果这个页面需要在
sideBar
显示,则在src/api/mock/menu.js
里添加一个菜单项
from react-antd-admin.
Related Issues (20)
- 右上角的 Notification通知提醒框遮挡了 注销... 等操作
- Error at logout HOT 8
- fix warning about PropTypes HOT 1
- React.creatClass is deprecated
- upgrade React to 15.6 or higher
- Error: Cannot find module '../src/components/Header/Header' when npm run test
- sh: now: command not found when npm run deploy HOT 2
- top nav for sidebar
- console print error: Uncaught TypeError: Cannot read property 'key' of undefined
- Hot reload not working very well
- remove extra validate function
- confused with router HOT 2
- what about browserHistory? HOT 2
- webpack source map doesent work? HOT 7
- babel-plugin-import 当设置 "style":true时样式未能引用是什么原因呢? HOT 6
- 如何在一个action执行成功之后调用另外一个Action,比如保存数据成功后查询数据 HOT 1
- close HOT 2
- npm run build 提示内存溢出是怎么回事啊 HOT 8
- 可以使用严格点的语法吗,好多Import in body of module; reorder to top import/first HOT 1
- 我按照流程运行了项目 但是报错了 报不能解析jsx的错误
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-antd-admin.