加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2路由器(@角/路由器),如何设置默认路由?

发布时间:2020-12-17 08:09:30 所属栏目:安全 来源:网络整理
导读:如何在我的@Routes路由元数据收集中设置默认路由?如果您使用@ angular / router-deprecated中的angular2路由器,您可以在@routeConfig对象中定义路由,该对象是路由对象的集合,但是这些路由对象在其上具有更多属性。例如,它们具有’name’和’useAsDefual
如何在我的@Routes路由元数据收集中设置默认路由?如果您使用@ angular / router-deprecated中的angular2路由器,您可以在@routeConfig对象中定义路由,该对象是路由对象的集合,但是这些路由对象在其上具有更多属性。例如,它们具有’name’和’useAsDefualt’属性,而从@ angular / router定义的路由不是。我想使用新的路由器编写我的新应用程序,但是如何使用新的路由器并设置默认路由?

这是我的主要应用程序组件,它定义了我的路线:

import { Component } from '@angular/core';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ConfigManagerComponent } from './configManager/configManager.component';
import { ApplicationMgmtComponent } from './applicationMgmt/applicationMgmt.component';
import { MergeComponent } from './merge/merge.component';

import { ROUTER_DIRECTIVES,Routes } from '@angular/router';


@Component({
    selector: 'app-container',templateUrl: 'app/app.component.html',directives: [ROUTER_DIRECTIVES]
})

@Routes([

        { path: '/Dashboard',component: DashboardComponent },{ path: '/ConfigManager',component: ConfigManagerComponent },{ path: '/Merge',component: MergeComponent },{ path: '/ApplicationManagement',component: ApplicationMgmtComponent }
])

export class AppComponent { }

当我点击这样的锚标签时,路线定义似乎工作正常:

<li class="nav hidden-xs"><a [routerLink]="['./Dashboard']">Dashboard</a>/li>

它转换到相关的路由。我唯一的问题是,当我的应用加载它没有路由活动。当我的应用程序启动时,我如何定义一个有效的默认路由?

谢谢!

V3-beta.2
RouterConfig = [
  { path: '',redirectTo: '/heroes',pathMatch: 'full' },{ path: 'heroes',component: HeroComponent,children: [
      { path: '',redirectTo: '/detail',{ path: 'detail',component: HeroDetailComponent }
    ] 
  }
];

还有全部路线

{ path: '**',

它重定向“无效”网址。

V3-alpha(vladivostok)

使用路径/和redirectTo

RouterConfig = [
  { path: '/',redirectTo: 'heroes',terminal: true },children: [
      { path: '/',redirectTo: 'detail',component: HeroDetailComponent }
    ] 
  }
];

RC.1 @ angular / router

RC路由器不支持使用AsDefault。作为解决方法,您可以明确浏览。

在根组件中

export class AppComponent {
  constructor(router:Router) {
    router.navigate(['/Merge']);
  }
}

用于其他组件

export class OtherComponent {
  constructor(private router:Router) {}

  routerOnActivate(curr: RouteSegment,prev?: RouteSegment,currTree?: RouteTree,prevTree?: RouteTree) : void {
    this.router.navigate(['SomeRoute'],curr);
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读