簡體   English   中英

如何使用反應路由器路由到絕對路徑?

[英]How to route to an absolute path using react router?

我有一個反應應用程序使用 react-router 在頁面之間路由。 問題是這樣的:我在以下路線的頁面中: http://example.com/my-current-location/我想路由到http://example.com/my-next-location/

我嘗試使用

this.props.history.push("/my-next-location")

但這將我帶到http://example.com/my-current-location/my-next-location/這不是我需要的。

this.props.history.push("/my-next-location")

我需要的是一種導航到絕對路徑的方法。 當然,

location.replace()

不會這樣做,因為我不想刷新整頁。 我怎樣才能做到這一點?

你可以使用<Link />或者這個組件

import React from 'react;
import {Redirect} from "react-router-dom";




/**
 * @param {boolean} props.redirect 
 */

const index = props =>{

return props.redirect ? 
<Redirect to="/my-next-location" />
:<div>
   the components code
</div>

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM