GithubHelp home page GithubHelp logo

Comments (6)

fireyy avatar fireyy commented on April 28, 2024 1

就是这个思路

from react-antd-admin.

fireyy avatar fireyy commented on April 28, 2024

index.js 里定义新的页面路由,具体可以看 react-router 的文档
接着换掉左侧菜单的链接为你新定义的路由地址

from react-antd-admin.

yipanbo avatar yipanbo commented on April 28, 2024

@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.

yipanbo avatar yipanbo commented on April 28, 2024

非常感谢!还有个问题,一会我再开个issue吧。

from react-antd-admin.

alwqx avatar alwqx commented on April 28, 2024

我也是初学者,准备定制这个手脚架。
基于现在最新的代码,关于左侧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.

fireyy avatar fireyy commented on April 28, 2024

@adolphlwq 这两者不一样,src/api/mock 里的数据代表模拟服务端下发的 menu 数据,用于页面显示,而 src/route 里代表的是这个应用支持的所有路由配置,所以新增一个页面的顺序是:

  1. src/route 里配置新 <Route />
  2. 如果这个页面需要在 sideBar 显示,则在 src/api/mock/menu.js 里添加一个菜单项

from react-antd-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.