Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在服务器端使用basename的动态段-React路由器_Reactjs_React Router_Isomorphic Javascript - Fatal编程技术网

Reactjs 在服务器端使用basename的动态段-React路由器

Reactjs 在服务器端使用basename的动态段-React路由器,reactjs,react-router,isomorphic-javascript,Reactjs,React Router,Isomorphic Javascript,我将以下代码写入我的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 'hist

我将以下代码写入我的
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
})
现在,当我稍微调整参数以检查问题所在时,我进行了以下更新

match({history,routes:getRoutes(store)},(错误,重定向位置,renderProps)

我最终得到了以下日志:

null { pathname: '/in/leagues',
  search: '',
  hash: '',
  state: null,
  action: 'REPLACE',
  key: 'meh7oq',
  basename: '/in',
  query: {} } undefined
是否缺少某些参数,或者此基本名称不适用于服务器端渲染

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
})
我还尝试在历史记录中使用
useBasename
函数

const memoryHistory = useBasename(createHistory)({
    basename: '/in'
});