route.config.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { Route } from 'react-router';
  3. import RecipesContainer from 'containers/Recipes';
  4. import CreateRecipe from 'containers/Recipes/Create';
  5. import ViewRecipe from 'containers/Recipes/View';
  6. import EditRecipe from 'containers/Recipes/Edit';
  7. import ShoppingList from 'containers/ShoppingCart/List';
  8. import PlannerContainer from 'containers/Planner';
  9. const emptyRoute = (title: string) => (props: any) => {
  10. return (<h1>{title} {props.match.params && props.match.params.id}</h1>);
  11. };
  12. const routes = [
  13. {
  14. path: '/recipes',
  15. component: RecipesContainer,
  16. routes: [{
  17. path: '/recipes/create',
  18. component: CreateRecipe,
  19. }, {
  20. path: '/recipes/view/:id',
  21. component: ViewRecipe
  22. },
  23. {
  24. path: '/recipes/edit/:id',
  25. component: EditRecipe,
  26. }]
  27. }, {
  28. path: '/planner',
  29. component: PlannerContainer,
  30. routes: [{
  31. path: '/planner/lala',
  32. component: emptyRoute('planner lala'),
  33. }]
  34. }, {
  35. path: '/shoplist',
  36. component: ShoppingList,
  37. }
  38. ];
  39. export const RouteWithSubRoutes = (route: any) => (
  40. <Route
  41. path={route.path}
  42. render={props => (
  43. <route.component location={props.location} routes={route.routes} {...props} />
  44. )}
  45. />
  46. );
  47. export default routes;