2016-12-15 67 views
0

我想知道如何讓我的LinkContainer/NavItem鏈接到外部URL。我想:帶有完整URL的LinkContainer - React-Bootstrap-Router

<LinkContainer to="https://www.example.com"> 
<NavItem eventKey={1}>LinkedIn</NavItem> 
</LinkContainer> 

在這種情況下,我得到的錯誤:

A path must be pathname + search + hash only, not a full URL

我也試過:

<NavItem eventKey={1} href="https://www.example.com"></NavItem>

以上的產量沒有錯誤,但沒有按什麼都不做。

回答

0

該組件基於react-routerLinkhttps://www.npmjs.com/package/react-router,並且僅用於在網站內部進行轉換。

例如:/people/people/id

,如果你想建立直接鏈接到其他網站,你必須與a href創建自己的鏈路組成部分。

0

使用Linkreact-router評論@yussan,你可以添加一個目標值,它應該工作。我用它來連接外部的社交網絡,像這樣:

import { Link } from 'react-router'

<Link to={"https://facebook.com/mypage"} target={'new'}>Facebook</Link>

我知道它的一個古老的線程,但我今天遇到這個問題,想和大家分享的解決方案。

你可能能夠做這樣的事情:

<Link to={"https://www.example.com"} target={'new'}> <NavItem eventKey={1}>LinkedIn</NavItem> </Link>

希望它能幫助,