0
我想实现我自己的UrlSerializer类,这是我做的:角2 - 实施UrlSerializer
import { UrlSerializer,UrlTree } from '@angular/router';
export class CustomUrlSerializer implements UrlSerializer {
parse(url: string): UrlTree {
// Change plus signs to encoded spaces
url.replace("%20", '-');
// Use the default serializer that you can import to just do the
// default parsing now that you have fixed the url.
return super.parse(url)
}
serialize(tree: UrlTree): string {
// Use the default serializer to create a url and replace any spaces with + signs
return super.serialize(tree).replace("%20", '-');
}
}
当我试图编译我得到以下误差修改:
c:/xampp/htdocs/proj/src/app/custom-url-serializer.ts (11,12): 'super' can only be referenced in a derived class.
c:/xampp/htdocs/proj/src/app/custom-url-serializer.ts (16,12): 'super' can only be referenced in a derived class.
怎么了?
UrlSerializer是一种抽象方法,现在我得到一个错误,我不能使用超级。我如何访问默认的URL序列化器? – TheUnreal
啊,是的,这是真的。你可以使用DefaultUrlSerializer https://angular.io/docs/ts/latest/api/router/index/DefaultUrlSerializer-class.html –
谢谢!但我如何将它导入到我的自定义类中?没有构造函数摘要 – TheUnreal