update route methods
This commit is contained in:
@ -19,11 +19,22 @@ const navigationIcon = [
|
||||
Gauge
|
||||
]
|
||||
|
||||
const convertToDashedString = (input: string): string => {
|
||||
// Menghapus tanda '/' di awal dan akhir string
|
||||
input = input.replace(/^\/+|\/+$/g, '');
|
||||
|
||||
// Membagi string menjadi bagian-bagian menggunakan '/'
|
||||
const parts = input.split('/');
|
||||
|
||||
// Menggabungkan bagian-bagian dengan tanda '-'
|
||||
return `/${parts.join('-')}`;
|
||||
}
|
||||
|
||||
export const convertRouteToMenu = (data: RouteRecordRaw[], basePath: string = '/home', iconIndex: number = 0): MenuItemModel[] => {
|
||||
return data.filter((i) => i.path !== '').map((item) => {
|
||||
const convertedItem: MenuItemModel = {
|
||||
name: item.name?.toString() || '',
|
||||
path: `${basePath}/${item.path}`,
|
||||
path: convertToDashedString(`${basePath}/${item.path}`).replace('/home-', '/home/'),
|
||||
expanded: false,
|
||||
icon: undefined,
|
||||
children: [],
|
||||
@ -37,4 +48,15 @@ export const convertRouteToMenu = (data: RouteRecordRaw[], basePath: string = '/
|
||||
|
||||
return convertedItem
|
||||
})
|
||||
}
|
||||
|
||||
export const removeExtraSlashes = (input: string): string => {
|
||||
// Menggunakan ekspresi reguler untuk mengganti tanda '/' lebih dari 2 dengan satu tanda '/'
|
||||
return input.replace(/\/{3,}/g, '/');
|
||||
}
|
||||
|
||||
export const hasMoreThanTwoSlashes = (input: string): boolean => {
|
||||
// Menggunakan ekspresi reguler untuk mencari tanda '/' lebih dari 2 kali
|
||||
const matches = input.match(/\//g);
|
||||
return matches ? matches.length > 2 : false;
|
||||
}
|
Reference in New Issue
Block a user