我是以这个命令“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 { }
请求各位大佬帮忙!网上查了重定向的方法并不好使,难道每一个path: ''都要重定向么?