September 2018
Beginner
156 pages
3h 28m
English
When rendering the React application on the server-side, it is also helpful to know whether the requested URL matches any of the existing routes in the application. Only if the route is available should the corresponding component be rendered on the server-side. However, if the route is not available, the user should be presented with a Page Not Found page (404). The matchPath function in the react-router package allows you match the requested URL against an object containing route-matching properties such as path, exact, strict, and sensitive:
import { matchPath } from 'react-router'app.use('*', (req, res) => { const isRouteAvailable = matchPath(req.url, { path: '/dashboard/', strict: true }); ...});Read now
Unlock full access