在不使用重定向或链接的情况下更改 react-router v4 中的 URL [英] Changing the URL in react-router v4 without using Redirect or Link

查看:19
本文介绍了在不使用重定向或链接的情况下更改 react-router v4 中的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-router v4material-ui 在我的 React 应用程序中.我想知道一旦点击 GridTile 后如何更改 URL="noreferrer">网格列表.

I'm using react-router v4 and material-ui in my React app. I was wondering how to change the URL once there is a click on a GridTile within GridList.

我最初的想法是为 onTouchTap 使用一个处理程序.但是,我可以看到重定向的唯一方法是使用组件 RedirectLink.如何在不呈现这两个组件的情况下更改 URL?

My initial idea was to use a handler for onTouchTap. However, the only way I can see to redirect is by using the components Redirect or Link. How could I change the URL without rendering those two components?

我试过 this.context.router.push('/foo') 但它似乎不起作用.

I've tried this.context.router.push('/foo') but it doesn't seem to work.

推荐答案

试试这个,

this.props.router.push('/foo')

警告适用于 v4 之前的版本

warning works for versions prior to v4

this.props.history.push('/foo')

对于v4 及以上

这篇关于在不使用重定向或链接的情况下更改 react-router v4 中的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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