melon_frontend/src/Router.tsx
Ruidy a9bf6936b5
refactoring (#18)
* chore: update deps to fix CVEs

* cleanup

* use variable for app routes

* refactor

* ⬆️ react router

* ⬆️ react

* delete pem files
2022-09-10 14:33:51 +02:00

62 lines
1.2 KiB
TypeScript

import { Route, Routes } from 'react-router-dom';
import BillPage from './pages/bill';
import BillsPage from './pages/bills';
import HomePage from './pages/home';
import NewBillPage from './pages/newBill';
import NotFoundPage from './pages/notFound';
import ReportPage from './pages/report';
type Params = {
path: string;
component: ({ ...props }: any) => JSX.Element;
};
export const AppRoutes = {
home: '/',
bills: '/bills',
reports: '/reports',
catchAll: '*'
};
export default function Router() {
const routes: Params[] = [
// Home
{
path: AppRoutes.home,
component: HomePage
},
// Bills
{
path: `${AppRoutes.bills}/new`,
component: NewBillPage
},
{
path: AppRoutes.bills,
component: BillsPage
},
{
path: `${AppRoutes.bills}/:id`,
component: BillPage
},
// Reports
{
path: AppRoutes.reports,
component: ReportPage
},
// … rest
{
path: AppRoutes.catchAll,
component: NotFoundPage
}
];
return (
<>
<Routes>
{routes.map(({ path, component: Component }) => (
<Route key={path} path={path} element={<Component />} />
))}
</Routes>
</>
);
}