Ui路由器未在加载

时间:2015-05-10 19:45:11

标签: angularjs angular-ui-router

我在我的项目中使用Angular UI路由器。

我已经设置好了,一切正常。除此之外,我需要明确点击localhost:8000/#/以加载我的项目。

当我使用ngRoutes时,没有遇到过这样的问题。

我的配置如下:

app.config(function($stateProvider,$urlRouterProvider, $locationProvider){
    $urlRouterProvider.otherwise('/');
    $stateProvider.state('index',{
        url: '/',
        templateUrl: '/testassets/partials/index.html',
        controller: 'indexCtrl'
    })
});

如何让url hashPrefix自动添加到网址?

1 个答案:

答案 0 :(得分:0)

尝试使用此代码在首次加载时或在索引页

时添加#/
app.config(function($stateProvider,$urlRouterProvider){
    $urlRouterProvider.when('', '/');
    $stateProvider.state('/', {
        url: '/',
        templateUrl: '/testassets/partials/index.html',
        controller: 'indexCtrl'
     })
});

相反,如果您想在索引中包含模板,则无需添加#/

即可使用
app.config(function ($stateProvider) {
    $stateProvider.state('index', {
        url: '',
        templateUrl: '/testassets/partials/index.html',
        controller: 'indexCtrl'
     })
});