我怎样才能走一条路并在反应路由器 dom 中附加一个新的 url



我目前的路径是 app/get-main/123/add-sub/ .我想导航到app/get-main/123/get-sub/123 .目前我正在通过以下方式执行此操作

id=123; this.props.history.push('/get-main/123/get-sub/'+id )

怎样才能以更好的方式实现这一目标,其中我从当前路由上升到app/get-main/123/,然后附加add-sub/id

您可以使用this.props.history.location.pathname获取当前的URL路径,以便执行以下操作:

this.props.history.push(`${this.props.history.location.pathname}get-main/123/get-sub/${id}`)

最新更新