state provider and route provider in angularJS

前端 未结 1 619
囚心锁ツ
囚心锁ツ 2020-12-15 06:57

Below is my app.js file

angular
  .module(\'repoApp\', [
    \'ngAnimate\',
    \'ngAria\',
    \'ngCookies\',
    \'ngMessages\',
    \'ngResource\',
    \'         


        
相关标签:
1条回答
  • 2020-12-15 07:40

    You shouldn't use both ngRoute and UI-router. Here's a sample code for UI-router:

    repoApp.config(function($stateProvider, $urlRouterProvider) {
      
      $stateProvider
        .state('state1', {
          url: "/state1",
          templateUrl: "partials/state1.html",
          controller: 'YourCtrl'
        })
        
        .state('state2', {
          url: "/state2",
          templateUrl: "partials/state2.html",
          controller: 'YourOtherCtrl'
        });
        $urlRouterProvider.otherwise("/state1");
    });
    //etc.

    You can find a great answer on the difference between these two in this thread: What is the difference between angular-route and angular-ui-router?

    You can also consult UI-Router's docs here: https://github.com/angular-ui/ui-router

    0 讨论(0)
提交回复
热议问题