2018-10-12 08:38:25   Visit  1220

在react中实现未匹配的路由显示404界面

// router.js
import React from \\\'react\\\';
import { Route, Switch } from \\\'react-router\\\';
import NotFound from \\\'../pages/NotFound\\\';
import Home from \\\"../pages/Home\\\";
import User from \\\"./user\\\";
import About from \\\"./about\\\";

const routeList = [
  User,
  About
];

export default (
  <Switch>// 重点
    <Route exact path=\\\'/\\\' component={Home} > </Route>
    {routeList}
    <Route component={NotFound} />
  </Switch>
);

©2017 Leechg.com