admin管理员组文章数量:1633991
1、引入
import { Router, Route, Switch } from 'dva/router';
2、使用
import React from 'react';
import { Router, Route, Switch } from 'dva/router';
import IndexPage from './routes/IndexPage/IndexPage';
import ProductPage from './routes/ProductPage/index'
function RouterConfig({ history }) {
return (
<Router history={history}>
<Switch>
<Route path="/" exact component={IndexPage} />
<Route path="/product" exact component={ProductPage} />
</Switch>
</Router>
);
}
export default RouterConfig;
3、注册路由,在index.js中
app.router(require('./router').default); .default将路由的RouterConfig配置出来
4、若将Hash路由模式替换成BrowserHistory
1、安装
cnpm install --save history
2、在主入口文件index.js中
import { createBrowserHistory as createHistory } from 'history';
3、改写初始化app
const app = dva({
history: createHistory(),
});
5、路由导航(除了routerRedux和引入方式,其余和react导航相同)
声明式导航:
import {Link,NavLink} from 'dva/router'
<Link to='/'>跳转</Link>
<NavLink to='/'>跳转</NavLink>
编程式导航:
方式一:
this.props.history.push('/url')
方式二:
import {routerRedux} from 'dva/router'
this.props.dispatch(routerRedux.push('/'));
其中:
此种方法不能连接model的方法
即export default connect(mapStateToProps)(App),不能有mapDispatchToProps,否则dispatch会未定义
版权声明:本文标题:dva 路由配置 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729177393a1188890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论