当我打开子URL时,它在我的本地环境中工作,比如
http://localhost:4200/login
. 但在我用
ng build --prod
所有子URL都无法在Live服务器上工作。
如果我使用
this.router.navigate(['/system']);
它在构建的项目中工作,但是如果我重新加载同一个URL,它将不工作(404)。
我的路由策略有什么问题吗?
索引文件
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<base href="/">
</head>
<body>
<app-root></app-root>
</body>
</html>
App.M.模块
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {HomeComponent} from './components/home/home.component';
import {HttpClientModule} from "@angular/common/http";
import {SystemComponent} from './components/system/system.component';
import {RouterModule, Routes} from '@angular/router';
import {AdminComponent} from './components/admin/admin.component';
const appRoutes: Routes = [
{path: '', component: HomeComponent}, // home pages
{path: 'login', component: HomeComponent},// sub page 1
{path: 'system', component: SystemComponent}, // sub page 2
{path: 'admin', component: AdminComponent} //sub page 3
];
@NgModule({
declarations: [
AppComponent,
HomeComponent,
SystemComponent,
AdminComponent
],
imports: [RouterModule.forRoot(
appRoutes,
{enableTracing: true},// <-- debugging purposes only it will show big console log data
{useHash: true} ),
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}