Route无法跳到404页面

#1

image
萌新请问,如果我这样设置了route,是不是永远也无法跳到404页面了?

#2

<Route path="/" exact component={MyLayout} />
这样就可以了, 指定 MyLayout 必须完全等于 / 才能匹配到路由

#3

但是如果加了exact之后,和上面设置了exact的redirect冲突了,很矛盾啊

#5
<Route path="/notMatch" />
<Route path="/" component={MyLayOut}/>
function MyLayout(){
  return (
   <>
     <header />
    <Switch>
      <Route path="/prod" />
     ....
      <Redirect to="/notMatch" />
    </Switch>
   </>
  )
}
#6

在这种配置了根 ‘/’ 路径之后的路由,是不是意味着已经无法再使用
<Redirect from="/" to="/login" />这种从根’/'路径的Redirect重定向了?
也就意味着一定要在myLayout加上一个中间路由:<Route path="/main" component={MyLayOut}></Route>以区分开?

#7

恩,一般在路径上要区别需要登陆的和不需要登陆的,这样好做验证
/public
/login
/admin/

#8

感谢大佬指导~