index.jsx 979 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { createBrowserRouter } from "react-router-dom";
  2. import Home from "../pages/Home";
  3. import My from "../pages/My";
  4. import List from "../pages/List";
  5. import Error from '../pages/Error';
  6. import Layout from "../Layout";
  7. import Detail from "../pages/Detail";
  8. const routes = [
  9. {
  10. path: '/',
  11. element: <Layout />,
  12. children: [
  13. {
  14. // 索引路由
  15. index: true,
  16. // path: 'home',
  17. element: <Home />
  18. },
  19. {
  20. path: 'my',
  21. element: <My />
  22. },
  23. {
  24. path: 'list',
  25. element: <List />
  26. }
  27. ]
  28. },
  29. {
  30. // listId 商品ID 动态参数
  31. path: '/detail/:listId/:title?',
  32. element: <Detail />
  33. },
  34. {
  35. // 兜底路由
  36. path: '*',
  37. element: <Error />
  38. }
  39. ]
  40. const router = createBrowserRouter(routes);
  41. export default router;