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 routeRedirect function redirect to relative url instead of route definition redirectTo #291

Closed why520crazy closed 1 year ago

why520crazy commented 1 year ago

修复缺陷:https://github.com/worktile/ngx-planet/issues/288

export class AppActualRootComponent {
    redirect = routeRedirect('dashboard');
}

使用 routeRedirect 函数传递相对路由地址,即可在组件中跳转路由,跳转时设置 replaceUrl 为 true,不在 URL 中生成当前组件的路由地址。

这个主要是因为如下的方案定义路由时, Angular 不会在 Location 中新增一个 state,所以如果单个应用这样处理点击回退时不会有 app1 的地址的。

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

但是微前端下就不行,app1 应用不会在 Location 加 state,但是其他应用会加,这就导致回退的时候变成了 app1,需要回退两次。

解决方案就是手动通过代码的方式跳转