相关疑难解决方法(0)

Angular 2 - 实现UrlSerializer

我正在尝试实现自己的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", '-');
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我得到以下错误:

c:/xampp/htdocs/proj/src/app/custom-url-serializer.ts (11,12): …
Run Code Online (Sandbox Code Playgroud)

angular

2
推荐指数
1
解决办法
3972
查看次数

标签 统计

angular ×1