清除Angularjs的URL

时间:2016-09-17 13:03:29

标签: angularjs angular-ui-router

我正在尝试为我的网络应用程序使用干净的URL路由,但我尝试的一切都不起作用。这是我的app.js.我不确定如何将位置提供程序添加到app.js中,但我尝试的所有内容都会生成404.请有人指出我的方向正确吗?

 .config(function($stateProvider, $urlRouterProvider) {
//Enable cross domain calls
    $stateProvider
        .state('main', {
            url: '/',
            templateUrl: 'views/main.html',
            controller: 'MainCtrl',
            controllerAs: 'vm'
        })
        .state('about', {
            url: '/about',
            templateUrl: 'views/about.html',
            controller: 'AboutCtrl',
            controllerAs: 'vm'
        })
        .state('blog', {
            url: '/blog',
            templateUrl: 'views/blog.html',
            controller: 'BlogCtrl',
            controllerAs: 'vm'
        })
        .state('corparate', {
            url: '/corparate',
            templateUrl: 'views/corparate.html',
            controller: 'CorparateCtrl',
            controllerAs: 'vm'
        })
        .state('contact', {
            url: '/contact',
            templateUrl: 'views/contact.html',
            controller: 'ContactCtrl',
            controllerAs: 'vm'
        })
        .state('login', {
           url: '/login',
           templateUrl: 'views/login.html',
           controller: 'RegisterationCtrl',
           controllerAs: 'vm'
        })
         .state('register', {
            url: '/register',
           templateUrl: 'views/register.html',
           controller: 'RegisterationCtrl',
           controllerAs: 'vm'
        })
        .state('dashboard', {
             url: '/dashboard',
             templateUrl: 'views/dashboard.html',
             controller: 'DashboardCtrl',
             controllerAs: 'vm'
              })
        .state('useredit', {
             url: '/settings',
             templateUrl: 'views/useredit.html',
             controller: 'UserEditCtrl',
             controllerAs: 'vm'
              })
        .state('friendlist', {
             url: '/search',
             templateUrl: 'views/friendlist.html',
             controller: 'FriendListCtrl',
             controllerAs: 'vm'
              })
        .state('friendprofile', {
             url: '/profile/:userName',
             templateUrl: 'views/friendprofile.html',
             controller: 'FriendProfileCtrl',
             controllerAs: 'vm'
              })
        .state('resetPassword', {
             url: '/resetPassword',
             templateUrl: 'views/resetPassword.html',
             controller: 'ResetPasswordCtrl',
             controllerAs: 'vm'
        });

    $urlRouterProvider.otherwise(function ($injector, $location) {
        var $state = $injector.get("$state");
        $state.go("main");
      });
})


.run(function ($rootScope, $state, ParseApi) {
  $rootScope.$on('$stateChangeStart', function (event, next) {
    if (!ParseApi.isAuthenticated()) {
      if (next.name !== 'register' && next.name !== 'login' && next.name !== 'resetPassword' && next.name !== 'friendlist' && next.name !== 'friendprofile') {
        event.preventDefault();
        $state.go('login');
      }
    }
  });
})

})();

0 个答案:

没有答案