mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-06 02:16:45 +00:00
use variable for app routes
This commit is contained in:
parent
01dce1b76a
commit
7ee04ddef0
2 changed files with 17 additions and 8 deletions
|
|
@ -12,38 +12,45 @@ type RouteConfig = {
|
|||
exact?: boolean;
|
||||
};
|
||||
|
||||
export const AppRoutes = {
|
||||
home: '/',
|
||||
bills: '/bills',
|
||||
reports: '/reports',
|
||||
catchAll: '*'
|
||||
};
|
||||
|
||||
export default function Router() {
|
||||
const routes: RouteConfig[] = [
|
||||
// Home
|
||||
{
|
||||
path: '/',
|
||||
path: AppRoutes.home,
|
||||
component: HomePage,
|
||||
exact: true
|
||||
},
|
||||
// Bills
|
||||
{
|
||||
path: '/bills/new',
|
||||
path: `${AppRoutes.bills}/new`,
|
||||
component: NewBillPage,
|
||||
exact: true
|
||||
},
|
||||
{
|
||||
path: '/bills',
|
||||
path: AppRoutes.bills,
|
||||
component: BillsPage,
|
||||
exact: true
|
||||
},
|
||||
{
|
||||
path: '/bills/:id',
|
||||
path: `${AppRoutes.bills}/:id`,
|
||||
component: BillPage
|
||||
},
|
||||
// Reports
|
||||
{
|
||||
path: '/reports',
|
||||
path: AppRoutes.reports,
|
||||
component: ReportPage,
|
||||
exact: true
|
||||
},
|
||||
// … rest
|
||||
{
|
||||
path: '*',
|
||||
path: AppRoutes.catchAll,
|
||||
component: NotFoundPage
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Layout, Menu, Row } from 'antd';
|
||||
import { Link, useRouteMatch } from 'react-router-dom';
|
||||
import { AppRoutes } from '../Router';
|
||||
|
||||
const { Header, Content, Footer } = Layout;
|
||||
|
||||
|
|
@ -8,8 +9,9 @@ export const withLayout =
|
|||
({ ...props }: any) => {
|
||||
const { url } = useRouteMatch();
|
||||
const menuItems = [
|
||||
{ label: 'Home', path: '/' },
|
||||
{ label: 'Bills', path: '/bills' }
|
||||
{ label: 'Home', path: AppRoutes.home },
|
||||
{ label: 'Bills', path: AppRoutes.bills },
|
||||
{ label: 'Reports', path: AppRoutes.reports }
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in a new issue