编辑: -我忘记说我用约曼和生成器-角(Grunt,Bower,角,角-路由)一起生成我的文件。
然后,我用了Grunt服务。。
只有当我点击我的菜单时,我在angularJS上的路由才能工作。当我在地址栏(地址栏)中键入url时,它说
Cannot GET /about顺便说一下,我用下面的教程从url中删除了hashtag:
https://scotch.io/quick-tips/pretty-urls-in-angularjs-removing-the-hashtag
当我点击菜单的时候,它工作得很好。
我的index.html菜单:
<!doctype html>
<html>
<head>
...
<base href="/">
</head>
<body ng-app="myApp">
...
<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-selected"><a href="/about" class="pure-menu-link">ABOUT</a></li>
<li class="pure-menu-item"><a href="/work" class="pure-menu-link">WORK</a></li>
<li class="pure-menu-item"><a href="/blog" class="pure-menu-link">BLOG</a></li>
<li class="pure-menu-item"><a href="/contact" class="pure-menu-link">CONTACT</a></li>
</ul>
...
</body
</html>我的路线app.js:
angular
.module('myApp', [
'ngAnimate',
'ngResource',
'ngRoute',
'ngTouch'
])
.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
redirectTo: '/about'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
controllerAs: 'about'
})
.otherwise({
redirectTo: '/'
});
//check browser support
if(window.history && window.history.pushState){
// if you don't wish to set base URL then use this
$locationProvider.html5Mode({
enabled: true
});
}
}]);解决方案
首先,您需要通过npm安装连接-modrewrite:
npm install --save-dev connect-modrewrite然后确保在Gruntfile.js顶部声明了以下内容:
var modRewrite = require('connect-modrewrite');最后一步:将其添加到Gruntfile.js中的中间件中
modRewrite(['^[^\\.]*$ /index.html [L]']),在这里,完整的代码:
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
modRewrite(['^[^\\.]*$ /index.html [L]']),
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},发布于 2015-09-28 22:09:09
解决方案
首先,您需要通过npm安装连接-modrewrite:
npm install --save-dev connect-modrewrite然后确保在Gruntfile.js顶部声明了以下内容:
var modRewrite = require('connect-modrewrite');最后一步:将其添加到Gruntfile.js中的中间件中
modRewrite(['^[^\\.]*$ /index.html [L]']),在这里,完整的代码:
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
modRewrite(['^[^\\.]*$ /index.html [L]']),
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},https://stackoverflow.com/questions/32813796
复制相似问题