angularjs - 如何解析作为路由Angular 1中查询参数的编码url?
问题描述
在我的路线中,我有这个。但是,我找不到正确解码 url 的方法。该页面只是重定向到基本 url(而不是重定向 url)。url 是这样编码/
的%2F
,什么不是,但我不知道如何制作它,所以我可以接受它作为查询参数。
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('example', {
url: '/{test}/{queryParameterUrl}',
controller: 'exampleCtrl as example',
template: require('./partials/test.html')
});
解决方案
在你的exampleController
你可以访问 state 参数,解析它并在以后使用它来重定向,如下所示:
app.controller('exampleCtrl', ['$state', function ($state) {
var exampleCtrl = this;
exampleCtrl.parsedRedirectUrl = $state.params.urlredirect.replace(/%2F/g, '/')
}]);
例如,在 HTML 中,使用链接重定向
<a href="{{example.parsedRedirectUrl}}">Redirect</a>
PS在您的状态定义中,使用controllerAs
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('example', {
url: '/{test}/{urlredirect}',
controller: 'exampleCtrl',
controllerAs: 'example',
template: require('./partials/test.html')
});
推荐阅读
- html - 如何使用 R 抓取 NSE 指数(NIFTY 50)的基本面数据
- excel - 从要包含的固定单元格中选择文本
- javascript - 未捕获的 SyntaxError:无效或意外的令牌 bundle.js:formatted:1
- mysql - 当我在 aws ubuntu 上安装 mysql 时发生错误
- google-cloud-platform - 使用什么机器实例在 Google Cloud Platform 中运行 GPU 工作负载
- html - 如何在不指定体重和高度的情况下制作全局占位符标签?
- powershell - Powershell - 如何运行位于另一台计算机上的脚本?
- c - 如何在一个makefile中编译多个项目
- php - php if 语句导致文件写入两次
- c++ - C++ 中 std::map 的运行时复杂度是多少?