安装后的grunt url无法正常工作?

时间:2016-12-28 07:13:19

标签: angularjs

enter image description here安装AngularJS Development与Yeoman,Grunt和Bower安装成功完成,然后使用grunt服务器运行服务器它也成功运行,但我的网址传递如下,

http://localhost:9010/#!/#%2F
http://localhost:9010/#!/#%2Fabout
http://localhost:9010/#!/#%2F

点击一下后,联系链接无法正常传递,如上所述,它没有得到,联系页面在我的安装过程中有任何问题或文件中的任何更改请给我解决方案。

'use strict';


  angular
.module('newangularApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function ($routeProvider) {
$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'MainCtrl',
    controllerAs: 'main'
  })
  .when('/about', {
    templateUrl: 'views/about.html',
    controller: 'AboutCtrl',
    controllerAs: 'about'
  })
  .otherwise({
    redirectTo: '/'
  });
 });

 (function(window, angular) {'use strict';


    function shallowCopy(src, dst) {
    if (isArray(src)) {
 dst = dst || [];

for (var i = 0, ii = src.length; i < ii; i++) {
  dst[i] = src[i];
}
} else if (isObject(src)) {
dst = dst || {};

for (var key in src) {
  if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
    dst[key] = src[key];
  }
     }
     }

 return dst || src;
  }
  var ngRouteModule = angular.
  module('ngRoute', []).
   provider('$route', $RouteProvider).
 // Ensure `$route` will be instantiated in time to capture the initial `$locationChangeSuccess`
  // event (unless explicitly disabled). This is necessary in case `ngView` is included in an
   // asynchronously loaded template.
  run(instantiateRoute);
   var $routeMinErr = angular.$$minErr('ngRoute');
   var isEagerInstantiationEnabled;

enter image description here

1 个答案:

答案 0 :(得分:1)

在代码中启用html5Mode

.config(function ($routeProvider, $locationProvider) {
$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'MainCtrl',
    controllerAs: 'main'
  })
  .when('/about', {
    templateUrl: 'views/about.html',
    controller: 'AboutCtrl',
    controllerAs: 'about'
  })
  .otherwise({
    redirectTo: '/'
  });
$locationProvider.html5Mode(true);
 });

现在从您的锚定元素(#)中删除<a>。这将解决您的问题。

在head section中添加index.html的<base href="/">