dynamic-segments using basename on the server side - React-Router

房东的猫 提交于 2019-12-24 07:53:27

问题


I have the following code written into my server.js for isomorphic rendering.

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
})

Now when I tweak the params a little to check where the issues may be, I made the following updates.

match({ history, routes: getRoutes(store) }, (error, redirectLocation, renderProps)

I ended up getting the following log:

null { pathname: '/in/leagues',
  search: '',
  hash: '',
  state: null,
  action: 'REPLACE',
  key: 'meh7oq',
  basename: '/in',
  query: {} } undefined

Is there some parameter I am missing or is this base name not meant for server side rendering.

I also tried using the useBasename function in history

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

来源:https://stackoverflow.com/questions/40171647/dynamic-segments-using-basename-on-the-server-side-react-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!