私はangle2アプリのルーティングを作ろうとしています。私はthisとthisのような多くの質問を見てきましたが、どれも私を助けませんでした。ここでRouterOutletMapのプロバイダはありません! in angle2 app
は私app.route.ts
次のとおりです。ここでは、その後
import { provideRouter, RouterConfig } from '@angular/router';
import {FormComponent} from './form.component';
import {AboutComponent} from './about-this.component';
const routes: RouterConfig = [
{ path:'home' , component: FormComponent },
{ path:'about', component: AboutComponent },
{ path:'**' , component: FormComponent }
];
export const appRouterProviders = [
provideRouter(routes)
]
とは、私のルートコンポーネントです:
import { ROUTER_DIRECTIVES, Router } from '@angular/router';
import { Component } from '@angular/core';
import {NavbarComponent} from './shared/navbar.component';
import {appRouterProviders} from './app.routes'
@Component({
moduleId: module.id,
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives:[NavbarComponent,ROUTER_DIRECTIVES],
providers: [appRouterProviders]
})
export class AppComponent {
title = "Here is Root!";
}
や寺では、(app.component.html
)です:
<router-outlet></router-outlet>
することができますように参照してください、私は./app.routes
私のルートプロバイダーとして使用されています。 結果として、私はhttp://localhost:4200/home
を使用するとフォームコンポーネントを取り込みますが、それは起こりません。また、コンソールにエラーはありません。 何が問題になりますか?
アップデート: 私も、main.ts
で私のアプリをブートストラップ:
import { bootstrap } from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {appRouterProviders } from './app.routes';
bootstrap(AppComponent,[appRouterProviders]);
ページが読み込まれたときに更新し、エラーが発生したかどうかを確認します。 – Bean0341