私のサーバに/clientpanel
ディレクトリからサービスを提供しています。だから私のURLはhttp://xxx.yy/clientpanel
です。クライアント側のすべてでサーバ側の反応ルータのベースネームを使用
const history = useRouterHistory(createHistory)({
basename: "/clientpanel"
});
render(
<Router history={history} routes={routes}/>,
document.getElementById("root")
);
だけで正常に動作します:これは私のクライアント側のコードです。すべてのURLは/clientpanel
に関連していますが、サーバーでこの作業を行う方法については問題があります。最初のページロードで
const history = useRouterHistory(createMemoryHistory)({
basename: "/clientpanel"
});
match({ routes, location: req.url, history}, (error, redirectLocation, renderProps) => {
if (renderProps) {
const html = renderToString(
<RouterContext {...renderProps}/>
);
res.send(renderFullPage(html))
}
});
私が最初<Link>
/clientpanel
をクリックした後、この作業を取得するには、URLに/clientpanel
を省略したが、その後、クライアント側にする必要があります初めに追加された:これは私のサーバー側のコードがあります。どのようにクライアントとサーバー側の両方で一貫して動作するようにするには?
'createMemoryHistory'は' basename'をサポートしていないようです。 'req.url'からベースネームを削除するだけで動作しますが、' Link'sは依然として壊れてしまいます。 –