use variable for app routes

This commit is contained in:
Ruidy 2022-03-10 11:12:43 -04:00
parent 01dce1b76a
commit 7ee04ddef0
2 changed files with 17 additions and 8 deletions

View file

@ -12,38 +12,45 @@ type RouteConfig = {
exact?: boolean; exact?: boolean;
}; };
export const AppRoutes = {
home: '/',
bills: '/bills',
reports: '/reports',
catchAll: '*'
};
export default function Router() { export default function Router() {
const routes: RouteConfig[] = [ const routes: RouteConfig[] = [
// Home // Home
{ {
path: '/', path: AppRoutes.home,
component: HomePage, component: HomePage,
exact: true exact: true
}, },
// Bills // Bills
{ {
path: '/bills/new', path: `${AppRoutes.bills}/new`,
component: NewBillPage, component: NewBillPage,
exact: true exact: true
}, },
{ {
path: '/bills', path: AppRoutes.bills,
component: BillsPage, component: BillsPage,
exact: true exact: true
}, },
{ {
path: '/bills/:id', path: `${AppRoutes.bills}/:id`,
component: BillPage component: BillPage
}, },
// Reports // Reports
{ {
path: '/reports', path: AppRoutes.reports,
component: ReportPage, component: ReportPage,
exact: true exact: true
}, },
// … rest // … rest
{ {
path: '*', path: AppRoutes.catchAll,
component: NotFoundPage component: NotFoundPage
} }
]; ];

View file

@ -1,5 +1,6 @@
import { Layout, Menu, Row } from 'antd'; import { Layout, Menu, Row } from 'antd';
import { Link, useRouteMatch } from 'react-router-dom'; import { Link, useRouteMatch } from 'react-router-dom';
import { AppRoutes } from '../Router';
const { Header, Content, Footer } = Layout; const { Header, Content, Footer } = Layout;
@ -8,8 +9,9 @@ export const withLayout =
({ ...props }: any) => { ({ ...props }: any) => {
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const menuItems = [ const menuItems = [
{ label: 'Home', path: '/' }, { label: 'Home', path: AppRoutes.home },
{ label: 'Bills', path: '/bills' } { label: 'Bills', path: AppRoutes.bills },
{ label: 'Reports', path: AppRoutes.reports }
]; ];
return ( return (