1

Я использую Webpack, реагирую, реагирую-маршрутизатор, реагирую-редукцию, редукцию и простой-редукционный маршрутизатор.Асинхронные маршруты вызывают ошибочную ошибку на серверной стороне

Я получил эту ошибку при использовании среагировать-маршрутизатор с асинхронными маршрутами и на стороне сервера визуализации:

bundle.js:1 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: 

(client) <noscript data-reacti 
(server) <div data-reactid=".1 

Мой routes.cjsx имеет это:

# Routes 
path: 'game' 
getComponent: (location, cb) => 
    require.ensure [], (require) => 
     cb null, require './views/game' 

Если изменить его это, я больше не получаю эту ошибку:

# Routes 
path: 'game' 
getComponent: (location, cb) => 
    cb null, require './views/game' 

Есть ли лучший способ справиться с этой проблемой при использовании асинхронных маршрутов?

ответ

1

Я получил это как You're trying to render a component to the document using server rendering but the checksum was invalid. This usually means you rendered a different component type or props on the client from the one on the server, or your render() methods are impure.

И установил его с помощью match на клиенте, как описано здесь: https://github.com/reactjs/react-router/blob/master/docs/guides/ServerRendering.md#async-routes

Док предлагает:

match({ history, routes }, (error, redirectLocation, renderProps) => { 
    render(<Router {...renderProps} />, mountNode) 
}) 

Конкретная без JSX стороне клиента код, который работает для меня (будет реорганизован немного):

var match = ReactRouter.match; 
var Router = React.createFactory(ReactRouter.Router); 
var Provider = React.createFactory(ReactRedux.Provider) 
match({ history: appHistory, routes: routes }, function (error, redirectLocation, renderProps) { 
    ReactDOM.render(
     Provider({store: store}, 
     Router(renderProps)), 
     $(document)[0] 
); 
});