我想爲我的angular2應用程序做一個路由。我看到很多問題,如this和this但他們都沒有幫助我。沒有RouterOutletMap的供應商!在angular2應用程序
這裏是我的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
它帶來了表單組件,但它不會發生。另外,控制檯中沒有錯誤。 什麼問題?
更新: 我也bootstraped我的應用程序main.ts
:
import { bootstrap } from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {appRouterProviders } from './app.routes';
bootstrap(AppComponent,[appRouterProviders]);
當您的頁面加載時,刷新它並查看是否發生錯誤。 – Bean0341