如果未找到路由,则以编程方式导航到服务器页面

时间:2016-04-17 20:15:04

标签: javascript reactjs react-router

我有超时后导航到某个网址的代码:

componentDidMount: function() {
    var self = this;
    setTimeout(function() { self.context.history.pushState(null, '/somePage'); }, 5000);
},

但我想要从服务器加载此页面,而不是SPA代码中的组件。 所以,当我这样做时,我只有:

Warning: Location "/somePage" did not match any routes

没有任何反应。 如何以正确的方式做到这一点? 谢谢。

1 个答案:

答案 0 :(得分:1)

你能使用:

window.location = "/somePage";

所以:

componentDidMount: function() {
  var self = this;
  setTimeout(function() { window.location="/somePage"; }, 5000);
},