%字符位于网址

时间:2017-05-09 15:13:07

标签: javascript angular typescript routing

我正在开发的网站的路由包含以下参数:

http://localhost:4200/v1/script/start=20170503&end=20170509&source=testname

这些参数中的一些用户可以自己创建这样的“源”。我对这些值进行编码,因此如果用户定义了source = %% PAGE %%,它将在url中显示为source =%2525%2525PAGE%2525%2525。我遇到的问题是,如果我手动输入网址:http://localhost:4200/v1/script/start=20170503&end=20170509&source=%%PAGE%%而不编码%符号,我会收到此错误:

URIError:URI格式错误     在decodeURIComponent(原生)     at getFilenameFromUrl(C:\ Users \ name \ Sites \ dashboard \ node_modules \ webpack-dev-middleware \ lib \ GetFilenameFromUrl.js:6:8)     在webpackDevMiddleware(C:\ Users \ name \ Sites \ dashboard \ node_modules \ webpack-dev-middleware \ middleware.js:39:18)     在Layer.handle [as handle_request](C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ layer.js:95:5)     在trim_prefix(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ index.js:317:13)     在C:\ Users \ name \ Sites \ anura-dashboard \ node_modules \ express \ lib \ router \ index.js:284:7     在Function.process_params(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ index.js:335:12)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ index.js:275:10)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:127:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)     在下一个(C:\ Users \ name \ Sites \ dashboard \ node_modules \ express \ lib \ router \ route.js:131:14)

我想捕获此错误并删除源或将用户注销,而不是获取空白屏幕和javascript错误。

1 个答案:

答案 0 :(得分:0)

我觉得这可能不是处理事情的最佳方式,但我还是让它继续工作:

尝试{

this.source = decodeURIComponent( urlParams['source'] );

);

} catch(错误){

this.source = urlParams['source'];

}