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

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

问题描述

我正在使用 react-router v4 material-ui 。我想知道如何在 GridTile 后更改URL / grid-listrel =noreferrer> GridList

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的处理程序。但是,我能看到重定向的唯一方法是使用组件 Redirect Link 。如何在不渲染这两个组件的情况下更改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天全站免登陆