是否可以从angular.js网址中删除#符号?
当我更改视图并使用params更新URL时,我仍然希望能够使用浏览器的后退按钮等,但我不想要#符号.
教程routeProvider声明如下:
angular.module('phonecat', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}).
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
otherwise({redirectTo: '/phones'});
}]);
Run Code Online (Sandbox Code Playgroud)
如果没有#,我可以编辑它以具有相同的功能吗?
我正在尝试实现html5的pushstate而不是Angularjs使用的#navigation.我试过搜索谷歌的答案,并尝试了角度irc聊天室,但没有运气.
这是我的controllers.js:
function PhoneListCtrl($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});
}
function PhoneDetailCtrl($scope, $routeParams) {
$scope.phoneId = $routeParams.phoneId;
}
function greetCntr($scope, $window) {
$scope.greet = function() {
$("#modal").slideDown();
}
}
Run Code Online (Sandbox Code Playgroud)
app.js
angular.module('phoneapp', []).
config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: PhoneListCtrl
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: PhoneDetailCtrl
}).
otherwise({
redirectTo: '/phones'
});
}])
Run Code Online (Sandbox Code Playgroud) 我上AngularJS项目的网址已经从localhost:3000/admin#/到localhost:3000/admin#!/自从上次我在我的项目工作...
没有在网上找到任何东西,有人知道这是什么?
我没有运气将htaccess规则转换为nginx重写.我已经检查了NginxRewriteModule文档,并完成了一些,但更复杂的是我不知所措.这就是我在看的内容:
RewriteRule ^$ /cgi-bin/index.cgi [L]
RewriteRule ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1 [L]
RewriteRule ^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 [L]
RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2 [L]
RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]
#RewriteRule ^Reseller\.html$ /cgi-bin/Templates/Pages/english/Reseller.html [L]
RewriteRule ^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles [L]
RewriteRule ^contact\.html$ /cgi-bin/index.cgi?op=contact [L]
RewriteRule ^premium\.html$ /cgi-bin/index.cgi?op=payments [L]
RewriteRule ^login\.html$ /cgi-bin/index.cgi?op=login [L]
RewriteRule ^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1 [L]
RewriteRule ^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1 [L]
RewriteRule ^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1 [L]
RewriteRule ^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1 [L]
RewriteRule ^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 [L,NC]
RewriteRule ^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1 [L]
RewriteRule ^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1 [L]
RewriteRule ^box$ /cgi-bin/index_box.cgi [L] …Run Code Online (Sandbox Code Playgroud) 使用AngularJS 1.3 <base>时,在HTML5模式下需要标记,这让我想到了HTML5模式与Hash模式的优点/缺点.
使用Hash模式时,缺点是如果您希望用户自己键入URL,则URL略显丑陋并且不直观.HTML5模式(1.3)的缺点是需要<base>标签,这可能会产生许多问题(比如使用SVG有点痛苦).
对于这两种模式我还有其他任何缺点吗?
有没有办法阻止浏览器插件注入HTML代码?
我有一个内置于angularjs的网站,但由于一些浏览器插件,我的路线搞砸了,这是我的angularjs中导致一些错误的HTML片段:
<script async="" src="http://b.scorecardresearch.com/beacon.js"></script>
<script type="text/javascript" async="" src="http://in1.perfectnavigator.com/d.php?id=57573&eid=&vdisp=0&u=http://www.domain.com/app/#/users&r=http://www.domain.com/site/profile/view/&vdisplayEn=0&vsliderEn=1&bannerAds=1&usadservEx=Oj45JDs7PTUiNg&lrc=0&curatedSite=0"></script>
<script type="text/javascript" src="https://api.jollywallet.com/affiliate/client?dist=111&sub=1&name=Browser%20Extensions"></script>
<script type="text/javascript" src="https://colo.cachefly.net/js/min.inject.js?id=Pz8sOCA"></script>
<script type="text/javascript" src="https://colo.cachefly.net/js/min.inject.js?id=Pz8sOis"></script>
<script type="text/javascript" src="https://colo.cachefly.net/js/min.inject.js?id=Pz8sOiA"></script>
<script type="text/javascript" src="https://colo.cachefly.net/js/min.inject.js?id=Pz8sOSA"></script>
<script type="text/javascript" src="https://colo.cachefly.net/js/min.inject.js?id=Pz8sOSs"></script>
<script type="text/javascript" src="http://www.superfish.com/ws/sf_main.jsp?dlsource=hhnkdzlc&CTID=ssaddon"></script>
<script type="text/javascript" src="http://istatic.datafastguru.info/fo/min/abc1RSQC.js"></script>
<script type="text/javascript" src="http://i.swebdpjs.info/sweb/javascript.js"></script>
<script type="text/javascript" src="http://cond01.etbxml.com/conduit_bundle/web/hotels.php?mamId=G8K2&userId=2222&appId=3333&&ui=1&ns=ETB_Hotels_Widget&partner=smg"></script>
<script type="text/javascript" src="http://cdn.visadd.com/script/14567725590/preload.js"></script>
<script type="text/javascript" src="https://www.tr553.com/InterYield/bindevent.do?e=click&affiliate=harel777&subid=iy&ecpm=0&debug=false&snoozeMinutes=1&adCountIntervalHours=24&maxAdCountsPerInterval=6&endpoint=https%3A%2F%2Fwww.tr553.com"></script>
<script type="text/javascript" src="https://intext.nav-links.com/js/intext.js?afid=wolfpack&subid=def&maxlinks=4&linkcolor=006bff&wiki=1"></script>
<script type="text/javascript" src="http://www.adcash.com/script/java.php?option=rotateur&r=234715"></script>
<script type="text/javascript" id="jw_00" src="//d2cnb4m0nke2lh.cloudfront.net/jollywallet/resources/js/2/affiliate_client.js"></script>
<script src="//jsgnr.datafastguru.info/fl/blm"></script>
<script src="//jsgnr.datafastguru.info/site-classification"></script>
<script src="//jsgnr.datafastguru.info/fl/blm"></script>
<script src="//jsgnr.datafastguru.info/bwl/wl"></script>
<script src="//jsgnr.datafastguru.info/fl/blm"></script>
<script src="//pstatic.datafastguru.info/fo/ecom/lang.js?c=in"></script>
<script src="//pstatic.datafastguru.info/rss/min/fo.min.js?v=2_3_621&b=dynamic&l=right"></script>
<script src="//jsgnr.datafastguru.info/bwl/wl?v=1"></script>
<script src="//jsgnr.datafastguru.info/site-classification"></script>
<script src="//pstatic.datafastguru.info/fo/ecom/lang.js?c=in"></script>
<script src="//jsgnr.datafastguru.info/bwl/wl?v=1"></script>
<script src="//pstatic.datafastguru.info/rb/min/fo.min.js?v=1_1_63"></script>
<script …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails + Devise进行登录和注册,但我的前端绝大多数都使用角度路由.当有人试图在没有登录的情况下转到特定页面时,我希望在成功登录后重定向它们.通常,这将是在会话中存储路径和修改after_sign_in_path_for方法的简单问题.但是,我似乎无法找到有效获取实际路径的Rails方法.我有信心我可以通过JS做到这一点,然后将其存储为cookie(或者真的是Angular),但我更喜欢将它保存在Rails中.有没有一种我想念的方法会给我一些实际的路径,包括/#/ what/whatever?
似乎以下应该有效:
request.original_url
Run Code Online (Sandbox Code Playgroud)
基于此(http://api.rubyonrails.org/classes/ActionDispatch/Request.html)
但它没有返回主题标签或以下参数.
也许是由于这个人说的话(没有哈希'#'的AngularJS路由)
#是一个旧的浏览器短路,它不会触发请求,这允许许多js框架在其上构建自己的客户端重新路由.
有没有一种干净的方法来收集Rails中的完整路径,还是我需要进入Angular/JS?
我是AngularJS的初学者并且有以下问题.我正在玩ngRoute模块,到目前为止这是我的代码:
HTML:
<nav ng-controller="navController as nav">
<ul>
<li ng-repeat="item in navItems">
<a href="{{ item.url }}">{{ item.name }}</a>
</li>
</ul>
</nav>
<div id="main">
<div ng-view></div>
</div>
Run Code Online (Sandbox Code Playgroud)
app.js
(function(window) {
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
.when('/contact', {
templateUrl : 'pages/contact.html',
controller : 'contactController'
});
if (window.history && window.history.pushState) {
$locationProvider.html5Mode(true);
}
}]);
app.controller('mainController', ['$scope', function($scope) {
$scope.message = 'Hello from home page';
}]);
app.controller('contactController', ['$scope', function($scope) { …Run Code Online (Sandbox Code Playgroud) 我有一个网页上有两个AngularJS应用程序.因为有两个应用程序,我必须将应用程序引导到页面上.我正在引导这样的应用程序:
// Bootstrap the first app
var app1 = angular.module('app-1', []);
app1.controller('App1Controller', ['$scope', '$window', function ($scope, $window) {
}]);
angular.bootstrap($('#app1'), ['app-1']);
// Bootstrap the second app
angular.bootstrap($('#app-2'), ['my-app-name']);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何完全关闭hashbang?我没有使用AngularJS进行视图管理.我正在将它用于其他事情.出于某种原因,当我使用带有Angular的IE8访问页面时,用户被重定向到其中包含hashbang的页面.hashbang导致服务器端错误.出于这个原因,我需要关闭它.我怎么做?
Polymer Starter Kit(PSK)包含有关在Firebase HERE上托管时使用Pretty URL的说明
我试图使用Nginx Server做类似的事情,但无法弄清楚页面重新加载的位置块.使用PSK附带的示例数据,您将如何配置"/ users/sam".
我是Angular的新手,我目前正在用ui.router做我的路线并对某些事情感到好奇.我注意到当我在localhost或在线访问我的网站时,我的网址包含/#/.主页看起来像domain.com/#/和其他页面关注套件(domain.com/#/about)如何让它显示没有哈希?
这是我的app.js的一个例子
var app = angular.module('dashboardApp', ['ui.router']);
app.config(
['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/');
$stateProvider
//Dashboard states and nested views ========================
.state('home', {
url: '/',
templateUrl: './templates/main/dashboard.html',
controller: 'dashboardCtrl'
})
//Subject states and nested views ==========================
.state('about', {
url: '/about',
templateUrl: './templates/main/about.html',
controller: 'aboutCtrl'
});
}]);
Run Code Online (Sandbox Code Playgroud)
以下是我在DOM中调用它的方式
<div class="main-nav">
<a ui-sref="home"><img src="randomimage.png" /></a>
</div>
<div class="main-nav">
<a ui-sref="about">About</a>
</div>
Run Code Online (Sandbox Code Playgroud) 实际上我在项目中使用的是角度5,我需要从网址中删除#。这是我的网址
http://localhost:4200/#/product/add。在我的域中发布后,它可以正常工作,但是在刷新页面时,由于我的网址中有#,它显示404错误。是否有可能做到这一点?
Need to remove # in url我在Angular中使用Laravel 5。
默认情况下,Angular添加/#/到URL。
我不喜欢它,/#/所以我$locationProvider.html5Mode(true);从Angular中删除了它。
现在,每当我尝试访问Angular URL时,Laravel都会拒绝重定向我,而是导致错误提示NotFoundHttpException:
抱歉,找不到您要查找的页面。
RouteCollection.php第161行中的NotFoundHttpException:
这是非常合乎逻辑的,因为未在Laravel的路由文件中定义该路由。
如何解决呢?
更多细节:
http://whatever.app/#/dashboard/home一切工作正常(laravel知道这是Angular路线,然后Angular删除了#,因此URL变得http://whatever.app/dashboard/home没有错误)。http://whatever.app/dashboard/homeLaravel时显示错误NotFoundHttpException。