Skip to content

Conversation

@why520crazy
Copy link
Member

@why520crazy why520crazy commented Aug 9, 2023

修复缺陷:#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,需要回退两次。

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

@why520crazy why520crazy merged commit 16dd203 into v15.x Aug 9, 2023
@why520crazy why520crazy deleted the feat-add-routeRedirect branch August 9, 2023 08:37
why520crazy added a commit that referenced this pull request Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants