限制导航以防止浏览器挂起并且浏览器在退出应用程序时挂起

时间:2020-03-30 22:48:19

标签: angular typescript canactivate angular-canload

我创建了AuthGuard并实现了canActivate接口:

'Declare the dictionary
Public DicoChildParent As Dictionary(Of Object, Object)

Sub AlimenterTreeview()
        Dim Tlst(14, 2)
        Dim i As Long
        Dim MyNeud As TreeNode

        Tlst(0, 0) = "Moteur"
        Tlst(1, 0) = "Cullase"
        Tlst(2, 0) = "Cylindre"
        Tlst(3, 0) = "Pompe a eau"
        Tlst(4, 0) = "Pompe a huile"
        Tlst(5, 0) = "Echappement"
        Tlst(6, 0) = "Circuit refroidissement"
        Tlst(7, 0) = "Radiateur"
        Tlst(8, 0) = "Tube radiateur"
        Tlst(9, 0) = "Purge"
        Tlst(10, 0) = "Join de cullase"
        Tlst(11, 0) = "Soupape"
        Tlst(12, 0) = "Carroserie"
        Tlst(13, 0) = "Fond de roulement"

        Tlst(0, 1) = ""
        Tlst(1, 1) = "Moteur"
        Tlst(2, 1) = "Moteur"
        Tlst(3, 1) = "Moteur"
        Tlst(4, 1) = "Moteur"
        Tlst(5, 1) = ""
        Tlst(6, 1) = ""
        Tlst(7, 1) = "Circuit refroidissement"
        Tlst(8, 1) = "Radiateur"
        Tlst(9, 1) = "Radiateur"
        Tlst(10, 1) = "Cullase"
        Tlst(11, 1) = "Moteur"
        Tlst(12, 1) = ""
        Tlst(13, 1) = "Join de cullase"


        DicoChildParent = New Dictionary(Of Object, Object)
        For i = 0 To UBound(Tlst) - 1
            With Form7.TreeView1
                If Len(Tlst(i, 1)) = 0 Then
                    If Not .Nodes.ContainsKey(Tlst(i, 0)) Then
                        .Nodes.Add(Tlst(i, 0), Tlst(i, 0))
                        DicoChildParent.Add(Tlst(i, 0), "x")
                    End If
                Else
                    DicoChildParent.Add(Tlst(i, 0), DicoChildParent(Tlst(i, 1)) & "###" & Tlst(i, 1))
                    MyNeud = GetParentNeud(DicoChildParent(Tlst(i, 0)).ToString, Form7.TreeView1)

                    If Not MyNeud Is Nothing Then
                        MyNeud.Nodes.Add(Tlst(i, 0), Tlst(i, 0))
                    End If
                End If
            End With
        Next

        Form7.ShowDialog()


    End Sub
``` vb.net
Public Function GetParentNeud(ByVal StrParent As String, ByVal Tree As TreeView)
        Dim Vect
        Dim i
        Dim Tmp As TreeNode

        On Error GoTo Erreur

        GetParentNeud = Nothing
        Vect = Split(StrParent, "###")
        Tmp = Tree.Nodes(Vect(1))
        If UBound(Vect) - 1 > 0 Then
            For i = 2 To UBound(Vect)
                Tmp = Tmp.Nodes(Vect(i))
            Next
        End If

        GetParentNeud = Tmp

Erreur: Exit Function

    End Function

Result :

[enter image description here][1]


  [1]: https://i.stack.imgur.com/ncG5p.png

下面是我的应用程序路由模块:

@Injectable()

export class AuthGuard implements CanActivate {
constructor(private userservice: UserAuthenticationService, private router: Router) { }
canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): boolean {
    if (this.userservice.isLoggedIn()) {

        return true;
    }else{
    this.router.navigateByUrl('')
    return false;
    }
  }
}

现在,每当我注销时,:

export const appRoutes: Routes = [

{
 path: '',
 component: Home,
 children: [
 { path: '', component: Login },
 { path: 'forgot-password', component: ForgotPassword }
 ]
 },
{
    path: 'dashboard',
    component: DashboardComponent,
    canActivate: [AuthGuard],
    pathMatch: 'full',
},
{
    path: 'dashboard/entity',
    component: EntityComponent
},
{
    path: 'Profile',
    component: ProfileComponent,
    pathMatch: 'full',
    canActivate: [AuthGuard]
},
{
    path: '**',
    component: DashboardComponent
}
];

@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

我的浏览器崩溃(挂起),控制台显示: 限制导航以防止浏览器挂起。参见https://crbug.com/882238。命令行开关--disable-ipc-flooding-protection可用于绕过保护

0 个答案:

没有答案