编码的 url 没有以角度正确重定向,如何将编码的 url 路由到正确的地址? [英] Encoded url is not redirecting properly in angular, how to route encoded url to proper address?

查看:39
本文介绍了编码的 url 没有以角度正确重定向,如何将编码的 url 路由到正确的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将编码的特殊字符 url 重定向到正确的地址?在我的项目编码 url 路由到网页.我创建了这样的路线

how to redirect encoded special characters url to proper address? in my project encoded url routing to web page. i created route something like this

{ path: 'welcome/:id', component: WelcomeComponent },

{ path: 'welcome/:id', component: WelcomeComponent },

实际上我正在传递网址http://localhost/welcome%3Fid%3D45但这不是接受它只接受http://localhost/welcome?id=45

actually i am passing url like http://localhost/welcome%3Fid%3D45 but this is not accepting and it is accepting only http://localhost/welcome?id=45

推荐答案

{path: '**', component: 'NotFoundComponent'}

export class NotFoundComponent{
constructor(private router:Router,
          private route: ActivatedRoute,
          ) { 
            let url = this.router.url;
            url = url.replace(/%40/gi, '@')
            .replace(/%3A/gi, ':')
            .replace(/%24/gi, '$')
            .replace(/%2C/gi, ',')
            .replace(/%3B/gi, ';')
            .replace(/%2B/gi, '+')
            .replace(/%3D/gi, '=')
            .replace(/%3F/gi, '?')
            .replace(/%2F/gi, '/');
            if(url !== this.router.url){
                 this.router.navigate([url]);
              }
}

这篇关于编码的 url 没有以角度正确重定向,如何将编码的 url 路由到正确的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆