每当我将“路由”添加到app.module.ts
app/app.routing.ts(18,23): error TS2304: Cannot find name 'ModuleWithProvider'.
[0] app/app.routing.ts(18,65): error TS2304: Cannot find name 'AppRoutes'.
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { SearchComponent } from './components/search/search.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { AboutComponent } from './components/about/about.component';
import { routing } from './app.routing';
@NgModule({
imports: [ BrowserModule, routing ],
declarations: [ AppComponent,
SearchComponent,
NavbarComponent,
AboutComponent],
bootstrap: [ AppComponent ]
})
export class AppModule { }
路由文件
import {ModuleWithProviders} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {SearchComponent} from './components/search/search.component';
import {AboutComponent} from './components/about/about.component';
const appRoutes: Routes = [
{
path:'',
component:SearchComponent
},
{
path:'about',
component:AboutComponent
}
];
export const routing: ModuleWithProvider = RouterModule.forRoot(AppRoutes);
答案 0 :(得分:0)
好的,这是解决方案。
您的代码中有两个拼写错误。
路由文件
import {ModuleWithProviders} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {SearchComponent} from './components/search/search.component';
import {AboutComponent} from './components/about/about.component';
const appRoutes: Routes = [
{
path:'',
component:SearchComponent
},
{
path:'about',
component:AboutComponent
}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
在最后一行,你编写了ModuleWithProvider而不是ModuleWithProvider s ,还有AppRoutes而不是 a ppRoutes