-1
我們該怎麼做?尤其是當部分路徑是param(:someParam)時。我在文檔中找不到任何東西。與反應路由器的相對鏈接
我們該怎麼做?尤其是當部分路徑是param(:someParam)時。我在文檔中找不到任何東西。與反應路由器的相對鏈接
現在,我們推薦使用反應-3路由器對於這種情況 https://github.com/ReactTraining/react-router/issues/3325
對於有這個問題,反應路由器2.x的人:
您可以使用browserHistory支持相對路徑,而不是使用鏈接組件。
// assuming http://site/myanimals
// configure router for hosting in subdirectory
const history = useRouterHistory(createHistory)({
basename: '/myanimals'
});
// then use it ...
import {browserHistory} from 'react-router';
browserHistory.push('about');
// or, for a configured route with 'animal/:id' you can use
// <Route path={'animal:id'} .../>
browserHistory.push('animal/3');
我希望這有助於!
你能解釋一下好嗎?舉個例子。 – Chris
無論如何,這是一個包。 https://github.com/ryanflorence/react-router-relative-links。 – omgj