React:我怎么能不只为一条路线添加basename?

问题描述 投票:1回答:1

我为所有路由使用基名:

`
const history = createHistory({ basename: basename });
`

但我不想在一个路由(/ callback)中使用basename:

`
<ConnectedRouter history={history}>
  <Switch>
    <Route path="/callback"/> //this one !
    <Route path="/login" component={Login} />
    <Route path="/" component={Home} />
  </Switch>
</ConnectedRouter>
`

我怎样才能做到这一点 ?

谢谢你的时间和回答:D

reactjs router
1个回答
0
投票

你不能拥有它的方式。您需要一个单独的历史记录来处理:

<OtherRouter history={historyWithNoBasename}>
  <Route path="/callback"/> 
</OtherRouter>
<ConnectedRouter history={history}>
  <Switch>
    <Route path="/login" component={Login} />
    <Route path="/" component={Home} />
  </Switch>
</ConnectedRouter>
© www.soinside.com 2019 - 2024. All rights reserved.