2017-12-09 5 views
0

私はリアクション、リアクタールーターv4のGoogleマップを使用しています(react-google-mapsのようなパッケージなし)。 React Router v4コンポーネント(NavLinkまたはLink)をinfowindowに配置する必要があります。 ReactDomServer.renderToString()を使用しようとしました。GoogleマップでNavLinkを追加infowindow(リアクション+リアクタールーターv4)

const infoWindowContent = ReactDOMServer.renderToString(
      <NavLink to="project/5">Show</NavLink> 
     ); 

this.infoWindow.setContent(infoWindowContent); 

Iから解決策を得た:生憎それは動作しませんRender react-router <Link> inside google InfoWindow

あなたは使用しないでください

またはwithRouter()<ルータ外>

このルータが範囲外であるため、かなり理解できます。

修正方法はありますか?

答えて

0

最後にhttps://github.com/istarkov/google-map-reactに切り替えました。これで問題が解決しました。


もう一つのアイデア(ダーティ液):グローバルウィンドウの変数で

入れ歴:

import createHistory from 'history/createBrowserHistory'; 

if (!window.AppHistory) { 
    window.AppHistory = createHistory(); 
} 

情報ウィンドウコンポーネントでは、次のように実行します。

const infoWindowContent = `<a class="infowindow" onclick="AppHistory.push('/project/${id}')">Show</a>`; 

this.infoWindow.setContent(infoWindowContent); 
関連する問題