React-router-redux 重定向到绝对 url

Cyr*_*PON 7 javascript routes reactjs react-router react-router-redux

我正在迁移一个反应应用程序,并试图拆分它。基本上,我想将一些客户端反应路由重定向到绝对网址(或相对网址,但至少进行服务器往返,其中完成了反向代理)

注意

现在一切都在反应之中。

路由看起来像这样:

<Provider store={store}>
  <Router history={history}>
    <Route path="/" component={Root}>
      <IndexRoute component={Home} />
      <Route path="/someroute1" component={Route1} />
      <Route path="/someroute2" component={Route2} />
      <Route path="/someroute3" component={Route3} />
    </Route>
  </Router>
</Provider>
Run Code Online (Sandbox Code Playgroud)

目标是将路由“/”和“/someroute2”重定向到静态 url(服务器 url)。就这样:

问题很简单:是否可以以干净的方式用绝对 url 替换 React 路由器路由?

我听说过 Redirect 和 IndexRedirect 组件,但我不知道如何正确使用它,而且,由于缺乏反应/反应路由器,我不知道是否会有任何危险的副作用(在历史上)例如)。

Cyr*_*PON 3

部分基于@brub 的回答,我找到了一个使用愚蠢组件的解决方案。

import React, { Component } from 'react'

export default class MyRedirectRoute extends Component {
  componentDidMount() {
    window.location.href = //my url here
  }
  render() {
    return null
  }
}
Run Code Online (Sandbox Code Playgroud)

我就这样过去了

<Route path="/someroute3" component={MyRedirectRoute} />
Run Code Online (Sandbox Code Playgroud)

尽管如此,我仍然不知道一些事情:

  • 这是推荐的解决方案吗?
  • 历史有副作用吗?
  • 有没有比 更好(更多反应路由器)的解决方案window.location.href?我尝试过this.context.history但没有成功...

在接受我自己的答案之前,我正在等待反馈/更好的解决方案