ルータを追加した後、AngularJS2アプリケーションコンポーネントがロードされません。ログにエラーはありません。私はルータを削除する場合、それは再び動作を開始します。誰もこの種の問題に直面していますか?私はアプリケーションを実行するために 'lite-server'を使用しています。ルータを追加した後にAngularJS2コンポーネントがロードされない
jsの角度バージョン: "2.4.0"、
ルータのバージョン: "〜3.4.8"、
LITE-サーバのバージョン: "^ 2.2.2"、
これはどのようにあります私は私のアプリにルータを追加します。
ステップ1:
ステップ2 index.htmlをする '<base href="/">
' を追加しました:私のcomponent.htmlに追加ルータのリンクは
<nav>
<a routerLink="/new">Contacts</a>
</nav>
<router-outlet></router-outlet>
は、ステップ3:私のrouter.tsは
以下のようになります。export const routes: Routes = [
{ path: '', component: ContactListComponent },
{ path: '/new', component: NewContactComponent },
{ path: '/about', component: AboutComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
ステップ4:以下
ようなモジュールに追加ルーティングコンポーネント210はまた
export class AppComponent {
constructor(private routes: Router) {
}
}
以下のようにルータを注入しようとしたので、誰もが私が間違っているのものを私に言うことができますか?あなたはおそらく(「パスは...スラッシュで始めることはできません。」)エラーが発生しますスラッシュ
export const routes: Routes = [
{ path: '', component: ContactListComponent },
{ path: 'new', component: NewContactComponent },
{ path: 'about', component: AboutComponent }
];
:
それは優れていました、私は完全に詰まっていました。返信ありがとう – evan
あなたの歓迎;) – mickdev