本文介绍了Angular2保留/添加尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,Angular2删除了斜杠.我已经设置了dotnet核心应用程序来添加它们,但是一旦加载js,它们就会被删除.

I have an issue with trailing slashes being removed by Angular2. I've setup my dotnet core application to add them, but they get removed as soon as the js get loaded in.

在Angular2中甚至有可能吗?

Is it even possible in Angular2?

(我的客户需要它,因此无需添加注释;不要使用斜杠).

(My client requires it, so no need to add a comment saying; don't use trailing slash).

谢谢.

应该添加的是,它与Angular2-Universal一起运行,因此升级角度版本不是那么容易:(

Should have added, this is running with Angular2-Universal, so upgrading the angular version is not that easy :(

推荐答案

在我们决定迁移到Angular4 Universal后,我们有了Angular的网站,我们的问题之一是在网站SEO上自动删除尾部的斜杠表示该功能,之后我们尝试了许多尝试,以类似于下面的代码(在app.module.ts文件中)防止这种无价之举的方法:

We have a website by Angular one, after we decided migrating to Angular4 Universal one of our problem was auto-removed trailing slash that efficacy on our site SEO, after many tries we found a hacky way for preventing this unvaluable action by same as below code(in app.module.ts file):

import { NgModule } from '@angular/core';
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';

import {AppComponent} from './app.component';


@Injectable()
export class UnstripTrailingSlashLocation extends Location {
  public static stripTrailingSlash(url: string): string {
    return url;
  }
}


Location.stripTrailingSlash = UnstripTrailingSlashLocation.stripTrailingSlash;

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [...],
  providers: [...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

这篇关于Angular2保留/添加尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:48