在IIS上使用UrlSerializer替换+的空格的IIS上运行angular 9应用程序时,使用+号重新加载url时出现404错误

问题描述

在角度9中,我正在使用UrlSerializer将空格替换为+号,如下所示。

import {UrlSerializer,UrlTree,DefaultUrlSerializer} from '@angular/router';

export class CustomUrlSerializer implements UrlSerializer {
    parse(url: any): UrlTree {
    alert(url);  // this alert is not coming when there is + or %2B included in url
    url = url.replace(/\+/g,'%20');
        let dus = new DefaultUrlSerializer();
        return dus.parse(url);
    }

    serialize(tree: UrlTree): any {
        let dus = new DefaultUrlSerializer(),path = dus.serialize(tree);
        return path.replace(/%20/g,'+');
    }
}

这在localhost中可以正常工作,但是当我在IIS中运行项目时,刷新带有+号的URL时出现404错误,其余URL都可以正常工作。

Ex. http//www.test.com/categories/popular+books -- this url gives 404 error on reload
    http//www.test.com/categories/popular%2Bbooks -- this url gives 404 error on reload
    http//www.test.com/categories/popularbooks -- this url works properly

enter image description here

任何人都可以让我知道如何在不使用HashLocationStrategy 的情况下使用 UrlSerializer解决此问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)