最近在玩react,用的是ant-design蚂蚁金服的框架,刚摸索到路由,懂了皮毛。在使用时发现浏览器发出小警告。具体入下。
一开始的代码,提示下图
BrowserRouter as Routerimport React from 'react'
import { Route, Switch, BrowserRouter } from 'react-router-dom'
import Home from '../pages/Home/Home'
import Login from '../pages/User/Login'
const BasicRoute = () => (
<BrowserRouter history={BrowserRouter}>
<Switch>
<Route exact path="/" component={Login}/>
<Route path="/Home" component={Home}/>
</Switch>
</BrowserRouter>
)
export default BasicRoute
改后的代码
import React from 'react'
import { Route, Switch, BrowserRouter as Router } from 'react-router-dom'
import Home from '../pages/Home/Home'
import Login from '../pages/User/Login'
const BasicRoute = () => (
<Router>
<Switch>
<Route exact path="/" component={Login}/>
<Route path="/Home" component={Home}/>
</Switch>
</Router>
)
export default BasicRoute
没毛病
没毛病放假前无聊记录下。不知道有啥用。
记录于2019-4-30 四月最后一天。迎接新的五月。加油。
网友评论