使用Spring-Data-Rest和Angular 2
%网址编码代码%25(http://www.w3schools.com/tags/ref_urlencode.asp)
首先;
http://localhost:4200/members/http%3A%2F%2Flocalhost%3A8080%2FErPApI%2Forganizations%2F1/detail
导航此网址并重新加载页面或复制粘贴新标签链接
%再次编码%25。 İts每次重新加载。
所以我失去了会员ID。我怎么能再次阻止编码%?
答案 0 :(得分:1)
当我收到链接时,我使用了以下方法。
decodeURIComponent()
答案 1 :(得分: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 { }