[英]If user visit any page of website first time and click backbutton, then how to land the user on home page
假設用戶訪問我網站的某個頁面。 這里用戶點擊了一些共享鏈接,這會在用戶瀏覽器中打開一個新選項卡。
現在如果用戶點擊后退按鈕,那么用戶應該登陸主頁而不是返回瀏覽器的空白頁面。
我嘗試使用 react-router 提供的 history.listen 方法。 但我無法將用戶重定向到主頁。
這是代碼片段
componentDidMount(){
this.props.history.listen((location, action) => {
if (action === 'POP') {
this.props.history.push('/homepage');
}
}
用戶應該從哪個頁面單擊返回按鈕以從新選項卡或同一選項卡返回。 如果您打開一個新選項卡用戶無法返回,因為該選項卡上沒有之前訪問過的頁面,如果您想在單擊共享按鈕后獲取用戶用戶,則可以在共享按鈕上設置單擊事件並獲取用戶返回首頁。
takeUserToHomepage=()=>{
this.props.history.push('/homepage')
}
<a target="_blank" onClick={this.takeUserToHomepage} href="https://www.naveenkashyap.com/">My Site</a>
https://github.com/ReactTraining/react-router/issues/6525- >嘗試參考此內容。 您可以創建代碼示例嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.