鍍金池/ 問(wèn)答/HTML/ angular4.x ng serve運(yùn)行沒(méi)有問(wèn)題但是打包后運(yùn)行說(shuō)沒(méi)有匹配的路由

angular4.x ng serve運(yùn)行沒(méi)有問(wèn)題但是打包后運(yùn)行說(shuō)沒(méi)有匹配的路由?

我是以這個(gè)命令“ng build --prod --aot --base-href ./”打的包!

app-routing.module.ts文件

import { ExtraOptions, RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';

const routes: Routes = [
    { path: '', loadChildren: 'app/home/home.module#HomeModule', pathMatch: 'full'}
];

const config: ExtraOptions = {
    useHash: false,
};

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

home-routing.module.ts文件

import {Routes, RouterModule} from '@angular/router';
import {HomeComponent} from './home.component';
import {NgModule} from '@angular/core';
import {HomeIndexComponent} from './home-index/home-index.component';

const routes: Routes = [
    {
        path: '',
        component: HomeComponent,
        pathMatch: 'full',
        children: [{
            path: '',
            component: HomeIndexComponent,
            pathMatch: 'full'
        }]
    }
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule],
    providers: []

})
export class HomeRoutingModule { }

app.module.ts文件

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpModule } from '@angular/http';
import { APP_BASE_HREF } from '@angular/common';

@NgModule({
  declarations: [
      AppComponent,
  ],
  imports: [
      BrowserModule,
      BrowserAnimationsModule,
      HttpModule,
      AppRoutingModule,
  ],
  providers: [
      { provide: APP_BASE_HREF, useValue: '/' }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

home.module.ts文件

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {HomeRoutingModule} from './home-routing.module';
import {HomeComponent} from './home.component';
import {HomeIndexComponent} from './home-index/home-index.component';
import {HomeHeaderComponent} from './home-header/home-header.component';
import { ElModule } from 'element-angular';
import {HomeFooterComponent} from './home-footer/home-footer.component';

const HOME_COMPONENTS = [
    HomeComponent,
    HomeHeaderComponent,
    HomeIndexComponent,
    HomeFooterComponent
];

@NgModule({
  imports: [
    CommonModule,
    HomeRoutingModule,
    ElModule.forRoot()
  ],
  declarations: [
      ...HOME_COMPONENTS
  ]
})
export class HomeModule { }

請(qǐng)求各位大佬幫忙!網(wǎng)上查了重定向的方法并不好使,難道每一個(gè)path: ''都要重定向么?

回答
編輯回答
魚(yú)梓

我已解決,但是要用redirect和hash,不然找不到頁(yè)面刷新丟失頁(yè)面!

2017年6月27日 05:03
編輯回答
拼未來(lái)

解決沒(méi),我也遇到這個(gè)問(wèn)題了

2018年4月11日 18:08