dva 路由配置
程序员文章站
2022-06-06 23:38:51
...
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配置出来
将Hash路由模式替换成BrowserHistory
1、安装
cnpm install --save history
2、在主入口文件index.js中
import { createBrowserHistory as createHistory } from 'history';
3、改写初始化app
const app = dva({
history: createHistory(),
});