Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法匹配任何路由。URL段:_Angular - Fatal编程技术网

Angular 无法匹配任何路由。URL段:

Angular 无法匹配任何路由。URL段:,angular,Angular,我是angular方面的新手,正在尝试配置路由,但遇到以下错误: Error: Cannot match any routes. URL Segment: 'news' 这是我的应用程序路由模块: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import{ RouterModule, Routes} from'@angular/router'; import{

我是angular方面的新手,正在尝试配置路由,但遇到以下错误:

Error: Cannot match any routes. URL Segment: 'news'
这是我的应用程序路由模块:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import{ RouterModule, Routes} from'@angular/router';
import{ myRoutes } from'./routes';

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forRoot(myRoutes)
  ],
  exports: [ RouterModule],
  declarations: []
})
export class AppRoutingModule { }
我的路由文件:

import{ Routes} from '@angular/router';
import { HomepageComponent } from '../homepage/homepage.component';
import { NewsComponent } from '../news/news.component';

export const myRoutes: Routes= [
    { path: 'homepage', component: HomepageComponent},
    { path: 'news', component: NewsComponent},
    { path: '', redirectTo: '/homepage', pathMatch: 'full' }
    ];
我的app.module.ts文件:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { AngularFontAwesomeModule } from 'angular-font-awesome';
import { HomepageComponent } from './homepage/homepage.component';
import { NewsComponent } from './news/news.component';
@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    FooterComponent,
    HomepageComponent,
    NewsComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AngularFontAwesomeModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
最后,我的app.component.html文件:

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>


当我尝试访问主页视图时,我遇到了相同的错误。

您可以尝试将您的路由放在文件
应用程序路由模块上吗

在这里找到一点:


你在导入这些路线吗?我看不到任何isue,除非你没有导入路线Where?我用这行代码导入了它们:import{myRoutes}from./routes';我试过了,没用。你认为这和角度有关吗?我使用的是7.0.6 Don think与您的版本无关,因为我将stackblitz更新到了最新版本,我对it@araujo你是否尝试重新构建你的项目,或者我的意思是停止服务并重新运行应用程序
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { NewsComponent } from './news/news.component';
import { HomepageComponent } from './homepage/homepage.component';

const routes: Routes = [
  { path: 'homepage', component: HomepageComponent},
  { path: 'news', component: NewsComponent},
  { path: '', redirectTo: '/homepage', pathMatch: 'full' }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }