原来我的情况是一个相当有边缘的情况,因此无法通过react-router很好地处理。
由于应用程序使用基于散列的历史(/#/path
),查询参数就是不能,如果他们不通过onEnter
的nextState
哈希之前逮住。
我最终做的是处理IndexRouter
内部的任何可能的查询。
<IndexRoute component={LoginPage}
onEnter={
(nextState, replaceWith) => {
console.log(nextState);
var obj = qs.parse(document.location.search.split("").slice(1,document.location.search.split("").length).join(""));
if(obj.gameid){
document.location.href = document.location.origin + document.location.pathname + "#/game/" + obj.gameid;
}
}
}
/>
这种方式似乎最好把路由逻辑内的容器应用程序的componentDidMount
因为路由逻辑Route
内部实际上属于。它还确保所有后续调用将正确处理。
向/ u/mrkre表示感谢,向onEnter指示我。
您可以尝试检查componentDidMount中的this.props.location.query,并在那里进行重定向,例如, 'if(this.props.location.query.gameid)' – mrkre
或者,您可以查看路由的onEnter方法,该方法允许访问nextState.location.query参数,并使用replace方法进行导航。 – mrkre