内部问号或angularjs的url有问题
Having problems with question marks inside or the url with angularjs
我在允许用户查看帖子名称中有问号或多个问号的帖子方面遇到了一些问题。当访问url mysite.com/posts/user/postname时,angular会拾取:user和:postname并检索必要的数据,但如果:postname包含一个或多个问号,则似乎会破坏路径,页面无法找到该帖子,因为它与带问号的实际帖子名称不匹配。但是,如果我用问号%3f的ascii版本键入postname,它会起作用并显示正确的数据。
我要么想重写url来替换?使用%3f或修复我的角度脚本。路线如下所示,控制器的相关部分如下所示。
.when('/posts/:postUser/:postName', {
title: 'View Post',
templateUrl: 'posts/view-post.php',
controller: 'userSingleCtrl',
resolve: {
post: function(services, $route) {
var postName = $route.current.params.postName;
var postUser = $route.current.params.postUser;
return services.getUserSingle(postName, postUser);
return services.getComments(postName, postUser);
}
}
})
控制器:
var postName = ($routeParams.postName) ? $routeParams.postName : 'Doesnt Exist';
var postUser = ($routeParams.postUser) ? $routeParams.postUser : 'Doesnt Exist';
var original = post.data;
original._name = postName;
original._user = postUser;
$scope.post = angular.copy(original);
$scope.post._name = postName;
$scope.post._user = postUser;
为了防止任何当前的htaccess规则导致这种情况,而不是实际的角度,我的htaccess也是如此。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /#/$1 [L,QSA]
<IfModule mod_expires.c>
ExpiresActive off
ExpiresByType text/html "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType text/plain "access 1 month"
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 2 days"
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "'.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
下面的链接显示了使用角度过滤器应用uri编码的示例。你可能会做同样的事情,你生成你的帖子链接来编码?(和其他字符)转换为有效的uri。
如何使用AngularJS生成url编码的锚链接?
相关文章:
- 这个条件语句的逻辑有问题
- 什么'这个javascript代码getElementById有问题
- 如何处理流星变量&对miniMongo有问题
- 如何使用javascript从同一浏览器下的其他页面获取URL?有可能吗
- 谷歌表单xml有问题
- Html、css和jQuery.我的代码有问题
- 有问题的突出显示(悬停)一个系列,突出显示图表
- D3 折线图示例 - 日期有问题
- 页面刷新后javascript内存泄漏有问题吗?为什么?
- 有问题的键代码186和222,如何捕捉它们
- 循环 += 十进制变量的 javascript 有问题
- 随机数生成器,what'我的方法/统计数据有问题吗?[JS]
- 为了在列表中搜索,角度过滤器有问题
- url的正则表达式有问题
- 内部问号或angularjs的url有问题
- 什么'我的{{url}}有问题
- 从URL中提取GET值有问题,不确定我做错了什么
- 在Javascript xmlhttp对象中打开相对URL有问题
- Javascript url重定向:这段代码有问题吗?
- 骨干网/rails之间使用REST url通信有问题