A
export function route(path: string, children: any = {}) {
const fn = function() {
return path
};
fn.toString = () => path;
fn.children = children;
for (let key in children) {
const item = children[key];
if (typeof item === 'string') {
fn[key] = route(path + item);
} else {
fn[key] = route(path + item(), item.children);
}
}
return fn
}
const routes = {
root: route('/'),
home: route('/home', {
user: route('/user', {
notifications: '/notifications',
settings: '/settings',
}),
dashboard: route('/dashboard'),
}),
};
console.log(routes.home.user.settings());