我将以下代码写入我的server.js
进行同构渲染。
import { match, useRouterHistory } from 'react-router';
import createHistory from 'react-router/lib/createMemoryHistory';
import createHistory from 'react-router/lib/createMemoryHistory';
import { useBasename } from 'history';
import getRoutes from './routes';
const client = new ApiClient(req);
const memoryHistory = useRouterHistory(createHistory)({
basename: '/in'
});
const store = createStore(memoryHistory, client);
const history = syncHistoryWithStore(memoryHistory, store);
match({ history, routes: getRoutes(store), location: req.originalUrl }, (error, redirectLocation, renderProps) => {
console.log(error, redirectLocation, renderProps)
// undefined, undefined, undefined returned
})
现在,当我稍微调整一下params来检查问题的位置时,我做了以下更新。
match({ history, routes: getRoutes(store) }, (error, redirectLocation, renderProps)
我最终获得了以下日志:
null { pathname: '/in/leagues',
search: '',
hash: '',
state: null,
action: 'REPLACE',
key: 'meh7oq',
basename: '/in',
query: {} } undefined
是否有一些我缺少的参数,或者这个基本名称不适用于服务器端渲染。
我也尝试过使用历史记录中的useBasename
功能
const memoryHistory = useBasename(createHistory)({
basename: '/in'
});