How to use the react-router.match function in react-router

To help you get started, we’ve selected a few react-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github papigers / question-it / server / server.jsx View on Github external
app.use((req, res, next) => {
  const css = [];

  const networkLayer = new Relay.DefaultNetworkLayer(GRAPHQL_URL, {
    headers: {
      cookie: req.headers.cookie,
    },
  });

  match({ routes, location: req.url }, (err, redirectLocation, renderProps) => {
    if (err) {
      // return res.status(500).end('Internal server error');
      next(err);
    }
    if (redirectLocation) {
      return res.redirect(redirectLocation.pathname + redirectLocation.search);
    }
    if (!renderProps) {
      return res.status(404).end('Not found.');
    }

    const render = function render({ data, props }) {
      const userAgent = req.headers['user-agent'];

      const InitialComponent = (
github compewter / whoof / src / helpers / universalRouter.js View on Github external
return new Promise((resolve, reject) => {
    match({routes, history, location}, (error, redirectLocation, renderProps) => {
      if (error) {
        return reject(error);
      }

      if (redirectLocation) {
        return resolve({
          redirectLocation
        });
      }

      if (history) {  // only on client side
        renderProps.history = history;
      }

      function resolveWithComponent() {
        const component = (
github bdefore / universal-redux / src / server / providers / react-router.js View on Github external
export function match(routes, location, store, cb) { // eslint-disable-line import/prefer-default-export
  reactRouterMatch({ history: createMemoryHistory(), routes, location }, cb);
}
github grommet / grommet-cms-boilerplate / server / isomorphicRender.js View on Github external
export default function isomorphicRender(req, res) {
  const location = createLocation(req.url);
  const authStatus = req.isAuthenticated();
  const store = configureStore({
    api: {
      url: process.env.API_URL
    },
    login: {
      loggedIn: authStatus,
      loginRequest: false,
      loginError: ''
    }
  });

  match({
    routes: getRoutes(store),
    location
  }, function(err, redirectLocation, renderProps) {
    if (err) {
      console.error(err);
      return res.status(500).end('Internal server error');
    }

    if (redirectLocation) {
      return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
    }

    if (!renderProps) {
      return res.status(404).end('Not found...');
    }
github LukeSheard / typescript-universal-boilerplate-react / src / server / middleware / render.tsx View on Github external
export default function render(
  req: Request,
  res: Response,
  next: NextFunction
): void {
  const history = createMemoryHistory({
    entries: [req.url]
  });
  const routes = createRoutes();

  match({ history, routes }, (error, redirectLocation, renderProps) => {
    if (error) {
      return next(error);
    } else if (redirectLocation) {
      return res
        .status(302)
        .redirect(redirectLocation.pathname + redirectLocation.search);
    } else if (renderProps) {
      res.status(200);
      res.write("");
      res.write(createPage(req, res, renderProps));
      return res.end();
    }

    return res.status(404).send("not-found");
  });
}
github flowcommerce / redux-fetch / examples / twitter / server / controllers / renderer.jsx View on Github external
return new Promise((resolve, reject) => {
    match(options, (error, redirectLocation, renderProps) => {
      if (error) reject(error);
      else resolve({ redirectLocation, renderProps });
    });
  });
}
github gearz-lab / react-vnav / demo / Server.js View on Github external
.use(function renderApp(req, res) {

            match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
                if (error) {
                    res.status(500).send(error.message)
                } else if (redirectLocation) {
                    res.redirect(302, redirectLocation.pathname + redirectLocation.search)
                } else if (renderProps) {

                    let wrap = require('../demo/pages/BasePage.txt')
                        .replace(/\$\{cssBundlePath\}/g, '')
                        .replace(/\$\{jsBundlePath\}/g, 'http://localhost:8082/assets/bundle.js');
                    res.status(200).send(wrap);

                } else {
                    res.status(404).send('Not found')
                }
            });
github andreypopp / sitegen / src / boot.js View on Github external
export function boot(routes: Route): void {
  match({routes, history}, (err, redirect, props) => {
    if (err) {
      throw err;
    } else if (redirect) {
      invariant(false, 'Redirects are not supported');
    } else {
      render(
        
          
        ,
        document.getElementById(HOST_ELEMENT)
      );
    }
  });
}
github isomorphic-dev-js / complete-isomorphic-example / src / middleware / renderView.jsx View on Github external
);
        const html = renderToString(
          
        );
        return res.send(`${html}`);
      }).catch(() => {
        return next();
      });
    } else {
      next();
    }
  };
  match(matchOpts, handleMatchResult);
}