我正在尝试在Angular 2中运行并运行一个测试应用程序,但是在使路由在最新版本的路由器(3.0.0 alpha-7)中工作时遇到了一些问题。
main.ts:
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {APP_ROUTER_PROVIDERS} from './app.routes';
bootstrap(AppComponent, [APP_ROUTER_PROVIDERS]);
app.component.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'my-app',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent { }
app.routes.ts:
import {provideRouter, RouterConfig} from '@angular/router';
import {SigninRoutes} from './signin/signin.routes';
export const AppRoutes: RouterConfig = [
...SigninRoutes
]
export const APP_ROUTER_PROVIDERS = [
provideRouter(AppRoutes)
];
signin.component.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class SigninComponent {
}
signin.routes.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class SigninComponent {
}
profile.component.ts:
import {Component} from '@angular/core';
@Component ({
selector: 'profile',
template: `
Profile Test
`
})
export class ProfileComponent {
}
出于某种原因,我可以启动该应用程序,但是尝试单击Profile RouterLink会导致错误:
“例外:错误:未捕获(承诺中):TypeError:无法读取未定义的属性'annotations'”
如果有人可以帮助我解决这个问题,将不胜感激。
听起来好像:
类似问题:
检查常见错误:
/
进入path
路线component
,redirectTo
,children
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句