Server-side reactive router does not display my routes

I am with version 1.0.0-rc1 and my match function will not display my route correctly.

This is my server

import express from 'express';
import React from 'react';
import createLocation from 'history/lib/createLocation'
import Router, { match, RoutingContext } from 'react-router';
import createRoutes from './create-routes';

const app = express();
const routes = createRoutes();

app.use((req, res) => {
  let location = createLocation(req.url);

  match({ routes, location }, (error, redirectLocation, renderProps) => {
    if (redirectLocation)
      res.status(301).redirect(redirectLocation.pathname + redirectLocation.search)
    else if (error)
      res.status(500).send(error.message)
    else if (renderProps == null)
      res.status(404).send('Not found')
    else
      res.send(React.renderToString(<RoutingContext {...renderProps}/>))
  });
});

export default app;

These are my routes.

import React from 'react';
import { Route } from 'react-router';
import Application from './components/Application.react';
import Home from './components/Home.react';

export default function() {
  return (
    <Route path="/" component={Application}>
      <Route path="home" component={Home} />
    </Route>
  );
}

What am I doing wrong in this? When I request / home, it should display <h1>Home</h1>instead <h1>Application</h1>. Just.

I based this on https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md

thanks

+4
source share
1 answer

. , "/home", , Home this.props.children . . :

( ):

<Route path="/" component={Application}>
<Route path="/home" component={Home} />

, Home

render() {
    return (
        <div>
            <h1>Application</h1>
            { this.props.children }
        </div>
    );
}
+1

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


All Articles