【问题标题】:Routing URL contains an Fragment (#) [duplicate]路由 URL 包含一个片段 (#) [重复]
【发布时间】:2019-06-12 03:49:38
【问题描述】:

我正在开发一个托管在 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

【问题讨论】:

  • @JohanRin 你说得对,我明天将构建该应用程序以检查它是否也适用于 S3 存储桶。如果是这样,我会将其标记为重复。

标签: angular angular-routing


【解决方案1】:

在你的 app-routing.module 中寻找这一行

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

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

PathLocationStrategy vs HashLocationStrategy in web apps

【讨论】:

  • 这正是我想要打开的选项;谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-06
相关资源
最近更新 更多