Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

react-router-dom 多个switch互相跳转,匹配不到页面

return (
<Router>

<Switch>
  <HomePage>
    <Switch>
      <ErrorBoundary>
        <Route exact path={'/'} component={InfoShow} />
      </ErrorBoundary>
    </Switch>
  </HomePage>
  <CompanyHome>
    <Switch>
      <ErrorBoundary>
        <Route path={ '/companyHome/companyBaseInfo'} component={CompanyBaseInfo} />
      </ErrorBoundary>
    </Switch>
  </CompanyHome>
  <Route component={NotFound} />
</Switch>

</Router>
);

有两个switch ,想要从'/'里面有个跳转到'companyHome/companyBaseInfo',但是出现了没有界面的问题
image.png

image.png

请问一下大家,路由该怎么写呀


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我没试过,但是可以尝试这么处理

<Switch>
    <Route path="/aaaa">
        <Switch>
            <Route path="/aaaa/aaaa">xxxx</Route>
            <Route path="/aaaa/aaaa">xxxx</Route>
        </Switch>
    </Route>

    <Route path="/bbb">
        <Switch>
            <Route path="/bbb/aaaa">xxxx</Route>
            <Route path="/bbb/aaaa">xxxx</Route>
        </Switch>
    </Route>
</Switch>

分在2个不同的Switch下,他们的path开头是不一样的,区分开


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...