问题
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