|
@@ -1,4 +1,4 @@
|
|
|
-import React from 'react';
|
|
|
|
|
|
|
+import React, { Component, FunctionComponent } from 'react';
|
|
|
import { Route } from 'react-router';
|
|
import { Route } from 'react-router';
|
|
|
import RecipesContainer from 'containers/Recipes';
|
|
import RecipesContainer from 'containers/Recipes';
|
|
|
import CreateRecipe from 'containers/Recipes/Create';
|
|
import CreateRecipe from 'containers/Recipes/Create';
|
|
@@ -6,46 +6,58 @@ import ViewRecipe from 'containers/Recipes/View';
|
|
|
import EditRecipe from 'containers/Recipes/Edit';
|
|
import EditRecipe from 'containers/Recipes/Edit';
|
|
|
import ShoppingList from 'containers/ShoppingCart/List';
|
|
import ShoppingList from 'containers/ShoppingCart/List';
|
|
|
import PlannerContainer from 'containers/Planner';
|
|
import PlannerContainer from 'containers/Planner';
|
|
|
-import { Redirect } from 'react-router-dom';
|
|
|
|
|
|
|
+import { Redirect, RouteComponentProps } from 'react-router-dom';
|
|
|
|
|
|
|
|
const emptyRoute = (title: string) => (props: any) => {
|
|
const emptyRoute = (title: string) => (props: any) => {
|
|
|
return (<h1>{title} {props.match.params && props.match.params.id}</h1>);
|
|
return (<h1>{title} {props.match.params && props.match.params.id}</h1>);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+type RouteType = {
|
|
|
|
|
+ path: string,
|
|
|
|
|
+ component: any
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface NavbarRoutesType extends RouteType {
|
|
|
|
|
+ routes?: RouteType[],
|
|
|
|
|
+ title: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export const navbarRoutes: NavbarRoutesType[] = [{
|
|
|
|
|
+ path: '/recipes',
|
|
|
|
|
+ title: 'recipes',
|
|
|
|
|
+ component: RecipesContainer,
|
|
|
|
|
+ routes: [{
|
|
|
|
|
+ path: '/recipes/create',
|
|
|
|
|
+ component: CreateRecipe,
|
|
|
|
|
+ }, {
|
|
|
|
|
+ path: '/recipes/view/:id',
|
|
|
|
|
+ component: ViewRecipe
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ path: '/recipes/edit/:id',
|
|
|
|
|
+ component: EditRecipe,
|
|
|
|
|
+ }],
|
|
|
|
|
+}, {
|
|
|
|
|
+ path: '/planner',
|
|
|
|
|
+ title: 'planner',
|
|
|
|
|
+ component: PlannerContainer,
|
|
|
|
|
+ routes: [{
|
|
|
|
|
+ path: '/planner/lala',
|
|
|
|
|
+ component: emptyRoute('planner lala'),
|
|
|
|
|
+ }],
|
|
|
|
|
+}, {
|
|
|
|
|
+ title: 'shoplist',
|
|
|
|
|
+ path: '/shoplist',
|
|
|
|
|
+ component: ShoppingList,
|
|
|
|
|
+}];
|
|
|
|
|
+
|
|
|
const routes = [
|
|
const routes = [
|
|
|
{
|
|
{
|
|
|
path: '/',
|
|
path: '/',
|
|
|
exact: true,
|
|
exact: true,
|
|
|
component: () => (<Redirect to='/recipes'/>)
|
|
component: () => (<Redirect to='/recipes'/>)
|
|
|
},
|
|
},
|
|
|
- {
|
|
|
|
|
- path: '/recipes',
|
|
|
|
|
- component: RecipesContainer,
|
|
|
|
|
- routes: [{
|
|
|
|
|
- path: '/recipes/create',
|
|
|
|
|
- component: CreateRecipe,
|
|
|
|
|
- }, {
|
|
|
|
|
- path: '/recipes/view/:id',
|
|
|
|
|
- component: ViewRecipe
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- path: '/recipes/edit/:id',
|
|
|
|
|
- component: EditRecipe,
|
|
|
|
|
- }],
|
|
|
|
|
- title: 'recipes'
|
|
|
|
|
- }, {
|
|
|
|
|
- path: '/planner',
|
|
|
|
|
- component: PlannerContainer,
|
|
|
|
|
- routes: [{
|
|
|
|
|
- path: '/planner/lala',
|
|
|
|
|
- component: emptyRoute('planner lala'),
|
|
|
|
|
- }],
|
|
|
|
|
- title: 'planner'
|
|
|
|
|
- }, {
|
|
|
|
|
- path: '/shoplist',
|
|
|
|
|
- component: ShoppingList,
|
|
|
|
|
- title: 'shoplist'
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ...navbarRoutes
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
export const RouteWithSubRoutes = (route: any) => {
|
|
export const RouteWithSubRoutes = (route: any) => {
|
|
@@ -53,7 +65,7 @@ export const RouteWithSubRoutes = (route: any) => {
|
|
|
<Route
|
|
<Route
|
|
|
path={route.path}
|
|
path={route.path}
|
|
|
render={props => (
|
|
render={props => (
|
|
|
- <route.component location={props.location} routes={route.routes} {...props} />
|
|
|
|
|
|
|
+ <route.component routes={route.routes} {...props} />
|
|
|
)}
|
|
)}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|