React-Router push 只更改 URL,不导航 [英] React-Router push only changes the URL and does not navigate

查看:54
本文介绍了React-Router push 只更改 URL,不导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 react-router 以编程方式导航,但我似乎无法这样做.

I am trying to programmatically navigate using react-router and I can't seem to be able to do so.

我已阅读其他相关问题,例如这个似乎有效对其他人,但无济于事.

I have read other related questions, such as this one that seems to work for everyone else, but to no avail.

我使用的是 react-router 版本 2.4.1,据我所知,它应该通过以下方式完成:

I am using react-router version 2.4.1, and to my understanding it should be accomplished by:

this.context.router.push('/');

甚至:

browserHistory = require('react-router').browserHistory;
//...
var browserHistory.push('/');

但无论采用哪种方法,我似乎都完成了 URL 重写,没有实际路由.

But with either approaces all I seem to accomplish is a URL rewrite, with no actual routing going on.

我的路由器上确实有一条为/"注册的路由.

I do have a route registered for '/' on my router.

我错过了什么?我离 window.location = '/' 几英寸远,否则是单页应用程序:(

What am I missing? I am inches away from a window.location = '/' on what is otherwise a Single Page Application :(

推荐答案

因此,显然应该归咎于摆弄上下文和子级的第三方组件.删除了它,现在它可以按预期工作了.

So, apparently a third-party component fiddling with the context and children was to blame. Removed it and now it works as expected.

如果有人遇到这种情况,请尝试查看路由上的组件如何处理上下文和子项.

If anyone is facing this, try to look at how the components on your route are handling context and children.

这篇关于React-Router push 只更改 URL,不导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆