我有代码在超时后导航到某个网址:
componentDidMount: function() {
var self = this;
setTimeout(function() { self.context.history.pushState(null, '/somePage'); }, 5000);
},
但我希望从服务器加载此页面,而不是作为 SPA 代码中的组件。 所以当我这样做时,我只需:
Warning: Location "/somePage" did not match any routes
什么也没发生。 如何以正确的方式去做呢? 谢谢。
最佳答案
你可以使用:
window.location = "/somePage";
所以:
componentDidMount: function() {
var self = this;
setTimeout(function() { window.location="/somePage"; }, 5000);
},
关于javascript - 如果找不到路由,则以编程方式导航到服务器页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36681697/