worktile / ngx-planet

🚀🌍🚀A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.
http://planet.ngnice.com
MIT License
537 stars 67 forks source link

feat: add redirectToRoute empty route #294

Closed why520crazy closed 1 year ago

why520crazy commented 1 year ago

使用 redirectToRoute('dashboard') 函数代替之前的:

 {
   path: '',
   redirectTo: 'dashboard',
   pathMatch: 'full'
},

使用方式如下:

export const routers: Route[] = [
    {
        path: 'app1',
        component: AppActualRootComponent,
        children: [
            // {
            //     path: '',
            //     redirectTo: 'dashboard',
            //     pathMatch: 'full'
            // },
            redirectToRoute('dashboard'),
            {
                path: 'dashboard',
                component: DashboardComponent
           }
           ...
];

redirectToRoute 函数会生成一个默认空路由,组件自动跳转到相对路由:

export function redirectToRoute(redirectTo: string): Route {
    return {
        path: '',
        component: RedirectToRouteComponent,
        data: {
            redirectTo: redirectTo
        }
    };
}