Angularjs Angular2:如何直接从根视图链接到(大)子视图
我正在试验Angular 2,遇到了一个我不确定如何调试的问题 示例情况 我有一个处理所有基本层路由的Angularjs Angular2:如何直接从根视图链接到(大)子视图,angularjs,angular,angular2-routing,Angularjs,Angular,Angular2 Routing,我正在试验Angular 2,遇到了一个我不确定如何调试的问题 示例情况 我有一个处理所有基本层路由的AppComponent,每个向下路由的“级别”都在该级别的新路由器上声明 我有以下路线: /主页,在AppComponent上定义 /应用程序,在AppComponent上定义 /应用程序/新,在ApplicationRouterComponent /应用程序/foo,在ApplicationRouterComponent 作为周围模板的一部分,有一个导航栏,所有页面都通用,因此需要能够链
AppComponent
,每个向下路由的“级别”都在该级别的新路由器上声明
我有以下路线:
- /主页,在AppComponent上定义
- /应用程序,在AppComponent上定义
- /应用程序/新,在
ApplicationRouterComponent
- /应用程序/foo,在
ApplicationRouterComponent
新应用程序
ApplicationRouterComponent
会被构造和显示,但NewApplication
组件不会
代码示例
appComponent.ts
import {Component} from 'angular2/core';
import {
RouteConfig,
ROUTER_DIRECTIVES,
ROUTER_PROVIDERS
} from 'angular2/router';
import {ApplicationRouterComponent} from './routes/application/applicationRouter';
import {HomeComponent} from './routes/home/homeComponent';
@Component({
selector: 'bop-application',
templateUrl: 'app/index.html',
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS],
})
@RouteConfig([
{ path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true },
{ path: '/applications/...', name: 'ApplicationRouter', component: ApplicationRouterComponent }
])
export class AppComponent { }
./app/routes/application/application路由器
import {Component} from 'angular2/core';
import {
RouteConfig,
ROUTER_DIRECTIVES,
ROUTER_PROVIDERS
} from 'angular2/router';
import {NewApplicationComponent} from './new/newApplicationComponent';
import {FooComponent} from './new/foo';
@Component({
selector: 'application-router',
templateUrl: 'app/routes/application/index.html',
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS],
})
@RouteConfig([
{ path: '/new', name: 'New', component: NewApplicationComponent},
{ path: '/foo', name: 'Foo', component: FooComponent},
])
export class ApplicationRouter {
constructor() {
debugger;
}
}
./app/index.html
<h1>Portal</h1>
<nav>
<a [routerLink]="['Home']">Home</a>
<a [routerLink]="['./ApplicationRouter/New']">New Application</a>
</nav>
<router-outlet></router-outlet>
Application Router
<router-outlet></router-outlet>
门户
家
新应用
./app/application/index.html
<h1>Portal</h1>
<nav>
<a [routerLink]="['Home']">Home</a>
<a [routerLink]="['./ApplicationRouter/New']">New Application</a>
</nav>
<router-outlet></router-outlet>
Application Router
<router-outlet></router-outlet>
应用路由器
./app/application/new/new.html
<h4>New View</h4>
新视图
路由器链接应为
<a [routerLink]="['/ApplicationRouter', 'New']">New Application</a>
新应用程序
路由器链接采用路由名称列表,而不是路径。支持的某些字符被解释为路径中的字符
用于从根路由器启动/xxx
用于从父路由器启动。
- 当前路由器的
(AFAIK冗余)/xxx
ROUTER\u提供程序
——仅在bootstrap(…)