1

我有一个问题。我UI-ROUTER在我的应用程序中使用 Angular.js。我在下面解释我的代码。

<li ui-sref-active="active"><a ui-sref="product.eVouchers.dashboard">Dashboard</a></li>

上面的 li 标签在输出下面生成

<a ui-sref="product.eVouchers.dashboard" href="/product/eVoucher/dashboard">Dashboard</a>

由于我尚未在 href 参数中删除 hash(#) 标记#<a ui-sref="product.eVouchers.dashboard" href="#/product/eVoucher/dashboard">Dashboard</a>因此只有当我试图通过右键单击在新选项卡中打开同一页面时,该页面才会出现。

我在下面解释我的路线文件。

   var Admin=angular.module('medilink',['ui.router','ngMessages','ngFileUpload','ui.bootstrap','720kb.datepicker']);
    Admin.run(function($rootScope, $state) {
          $rootScope.$state = $state;
        });
    Admin.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
        $urlRouterProvider.otherwise('/product');
        $stateProvider
         .state('product', { 
                url: '/product',
                templateUrl: 'productview/product.html',
                controller: 'productController'
            })
        .state('product.eVouchers',{
            url:'/eVoucher',
            templateUrl:'VoucherView/mas.html',
            controller: 'eVoucherController'
        })
        .state('product.eVouchers.dashboard',{
            url:'/dashboard',
            templateUrl:'VoucherView/dashboard.html',
            controller: 'dashboardController'
        })
       $locationProvider.html5Mode({
      enabled: false
    });
    });

在这里,我需要将#标签作为 href 参数与生成的 html 输出中的其他值一起使用。请帮我解决这个问题。

4

2 回答 2

0

关闭 html5Mode

$locationProvider.html5Mode(false)

如果它不起作用,可能你的 AngularJS 版本是 v1.3.x。这是 AngularJS v1.3.x 中的一个错误,请参阅问题报告

只需将 angular.js 更新到最新的 v1.5.7,并将 angular-ui-router.js 更新到 v0.2.11。它会起作用的。

于 2016-07-17T14:39:55.513 回答
0

这个问题似乎与 HTML 5 模式有关。检查文档:

$location 的 AngularJS 文档

只需将其关闭:

.config(['$locationProvider',
    function ($locationProvider) {

        // html 5 mode is by default turned off, so be sure 
        // that it is not turned on somewhere
        $locationProvider.html5Mode({enabled:false});
}]);
于 2015-12-19T14:27:06.020 回答