3

© 使用 Spring-Data-Rest 和 Angular 2

% URL 编码代码 %25 ( http://www.w3schools.com/tags/ref_urlencode.asp )

首先;

http://localhost:4200/members/http%3A%2F%2Flocalhost%3A8080%2FErPApI%2Forganizations%2F1/detail

当导航此 URL 并再次重新加载页面或复制粘贴新选项卡链接时

% 再次编码 %25。İts 每次重新加载。

http://localhost:4200/members/http%253A%252F%252Flocalhost%253A8080%252FErPApI%252Forganizations%252F1/detail

所以我丢失了会员ID。我怎样才能再次阻止编码%?

4

2 回答 2

2

获取链接时,我使用了以下方法。

 decodeURIComponent()
于 2017-05-11T13:29:37.070 回答
0

我将提供程序自定义 UrlSerializer 添加到根 AppModule。

像这样...

// custom-url-serializer.ts
import { DefaultUrlSerializer, UrlSerializer, UrlTree } from '@angular/router';
export class CustomUrlSerializer implements UrlSerializer {
    private defaultUrlSerializer: DefaultUrlSerializer = new DefaultUrlSerializer();

    parse(url: string): UrlTree {
        url = url.replace(/\%/g, '%25');
        return this.defaultUrlSerializer.parse(url);
    }

    serialize(tree: UrlTree): string {
        return this.defaultUrlSerializer.serialize(tree).replace(/%25/g, '%');
    }
}



// app.module.ts
import { NgModule } from '@angular/core';
import { CustomUrlSerializer } from './shared/custom-url-serializer';

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        ...
    ],
    bootstrap: [AppComponent],
    providers: [
        {
            provide: UrlSerializer,
            useClass: CustomUrlSerializer,    // <-- Here!
        },
    ],
})
export class AppModule { }
于 2018-04-13T02:17:29.860 回答