<Switch>
<Route exact path="/" component={App}/>
<Route path="/home" component={Dashboard}/>
<Route component={NotFound}/>
</Switch>
当我的网址是http://localhost:8080/home1
时,我将重定向到404页面,但是当我用子路径(http://localhost:8080/home/1
给出了错误的网址时,它无法呈现我的NotFound
组件并显示空屏幕。有人可以建议我我所缺少的吗?
答案 0 :(得分:1)
<Switch>
<Route exact path="/" component={App}/>
<Route path="/home" component={Dashboard}/>
<Route path="*" component={NotFound}/>
</Switch>