这样配置好以后,每次调用Route都会报错“You tried to redirect to the same route you're currently on: "/home"”请问该怎么优化呢? <Router> <div> <Nav/> <Redirect to="/home"></Redirect> <Route path="/comment" component={CommentBox}></Route> <Route path="/home" component={Home}></Route> <Route path="/productList" component={ProductList}></Route> <Route path="/showdetail" component={ShowDetail}></Route> <Route path="/showdetail/:id" component={ShowDetail}></Route> <Route path="/login" component={Login}></Route> <Route path="/private" component={Private}></Route> </div> </Router>
2 回答
波斯汪
TA贡献1811条经验 获得超4个赞
<Router>
<div>
<Nav/>
<Route path="/" render={() => (<Redirect to="/home"/>)}></Route >
<Route path="/comment" component={CommentBox}></Route>
<Route path="/home" component={Home}></Route>
<Route path="/productList" component={ProductList}></Route>
<Route path="/showdetail" component={ShowDetail}></Route>
<Route path="/showdetail/:id" component={ShowDetail}></Route>
<Route path="/login" component={Login}></Route>
<Route path="/private" component={Private}></Route>
</div>
</Router>
添加回答
举报
0/150
提交
取消