Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k 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 Reply

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开头是不一样的,区分开


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...