Server-side Router / Hapi Recovery Error

I struggled with this for a while, and before it worked, but inexplicably, it broke again, so the root cause was not resolved.

React Router v: 2.0.0-rc4

Problem: When the page loads, the server returns the following error.

Warning: Failed propType: Required prop `router` was not specified in `RouterContext`.
Warning: Failed propType: Required prop `location` was not specified in `RouterContext`.
Warning: Failed propType: Required prop `routes` was not specified in `RouterContext`.
Warning: Failed propType: Required prop `params` was not specified in `RouterContext`.
Warning: Failed propType: Required prop `components` was not specified in `RouterContext`.
Warning: [react-router] `<RouterContext>` expects a `router` rather than a `history`

Typically, the page loads, and client-side routing is working fine.

corresponding snippet from Server.js:

import routeConfig from './../common/routes/Routes.js';

const handleRender = function(req, res) {
    const initialState = {
                profile: {
                    name: 'Bob',
                    age: 10
                },
                messages: []
            }
    const createStoreWithMiddleware = applyMiddleware( thunkMiddleware)(createStore);
    const store = createStoreWithMiddleware(reducer(initialState));


    match({routes: routeConfig, location: req.url}, (error, redirectLocation, renderProps) => {
        // res(req.url);
        if(error) {
            res('error' + error.message);
        }
        else {
            res(renderProps);
            const html = renderToString(
            <Provider store={store}>
                <RouterContext {...renderProps} />
            </Provider>
            );

            //const initialState = store.getState();

            //res(renderFullPage(html, initialState));
        }
    });
}

Here is what is exported from Routes.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import { Route } from 'react-router';

//Components
import App from './../components/App.jsx';
import Name from './../components/Name.jsx';
import Profile from './../components/Profile.jsx';
import Messages from './../components/Messages.jsx';

const routeConfig = [
    {
        path: '/',
        component: App,
        childRoutes: [
            {path: 'test', component: Name},
            {path: 'profile', component: Profile},
            {path: 'messages', component: Messages}
        ]
    }
];

export default routeConfig;

When I upload renderprops, this is what I get

{
routes: [
{
path: "/",
childRoutes: [
{
path: "test"
},
{
path: "profile"
},
{
path: "messages"
}
]
},
{
path: "test"
}
],
params: { },
location: {
protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null,
search: null,
query: { },
pathname: "/test",
path: "/test",
href: "/test"
},
components: [
null,
null
],
history: {
__v2_compatible__: true
},
router: {
__v2_compatible__: true
}
}

So it seems that it never matches the components. Perhaps I passed req.url incorrectly? But I can’t find a defendant documenter that exactly indicates what this argument should look like.

+4
2

, , - - .

Good , /favicon.ico, , .

- / Hapi.

+11

, , , Github ( , ), , - . undefined ( - localhost: 8080/), this .

console.log('req.url:', req.url) app.get , , .

II: appHTML , , res.send().

+1

Source: https://habr.com/ru/post/1622742/


All Articles