Angular 2子路由(v3)'无法读取未定义的属性'annotations'' [英] Angular 2 Child Routing (v3) 'Cannot read property 'annotations' of undefined'

查看:61
本文介绍了Angular 2子路由(v3)'无法读取未定义的属性'annotations''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angular 2中运行并运行测试应用程序,但是在使路由在最新版本的路由器(3.0.0 alpha-7)中工作时遇到了一些问题.

I'm trying to play around in Angular 2 and get a test app running but I'm having some problems getting the routing to work in the latest version of the router (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:

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:

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:

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:

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:

profile.component.ts:

import {Component} from '@angular/core';

@Component ({
    selector: 'profile',
    template: `
        Profile Test
    `

})

export class ProfileComponent {

}

出于某种原因,我可以启动应用程序,但是尝试单击Profile RouterLink会导致错误:

For some reason, I can initiate the app alright, but attempting to click the Profile routerLink results in the error:

例外:错误:未捕获(承诺中):TypeError:无法读取未定义的属性'注释'"

"EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'annotations' of undefined"

如果有人可以帮助我解决这个问题,将不胜感激.

If anyone could help me out with this, it'd be much appreciated.

推荐答案

听起来像:

类似的问题:

  • https://github.com/angular/angular/issues/9427
  • https://github.com/AngularClass/webpack-toolkit/issues/1

检查常见错误:

  • 确保您的路线path中没有/
  • 确保每个路线都具有componentredirectTochildren
  • 之一
  • 确保将路由中使用的组件正确导入到定义了路由的文件中
  • Ensure you don't have / in path of your routes
  • Ensure every route has one of component, redirectTo, children
  • Ensure the components used in the routes are properly imported to the files where the routes are defined

这篇关于Angular 2子路由(v3)'无法读取未定义的属性'annotations''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆