路由 URL 包含片段 (#)

Routing URL contains an Fragment (#)

我正在开发托管在 AWS s3 存储桶上的 angular 应用程序(版本 6)。

我的应用 url 路由中有一点 #,它不会破坏我的路由或者根本不是问题。无论如何,我试图摆脱 # 但到目前为止没有成功。

一个小例子:

http://localhost:4200/#/Login 应该是 http://localhost:4200/Login

摆脱 # 的最佳方法是什么?

app-routing.module.ts

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

 // ----- Import of all the Components
 ...

export const routes: Routes = [

  { path: '', component: LoginComponent },
  { path: 'Login', component: LoginComponent },
  { path: 'signup', component: signupComponent },
  { path: 'Password', component: PasswordResetComponent, data: {title: 'Passwort Reset'} },
  { path: 'password', component: PasswordResetComponent, data: {title: 'Passwort Reset'} },
  { path: 'confirmation', component: LoginComponent },
  { path: 'Error', component: ErrorPageComponent, data: {title: 'ERROR'} },

export const routing = RouterModule.forRoot(routes);

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

app.module.ts中我只是导入了AppRoutingModule

在您的应用程序中-routing.module寻找这一行

RouterModule.forRoot(routes, {useHash : true}) //<= Change this boolean to false

目前有2个路由策略 查看这个单独的相关答案以进一步了解差异