Can I have a single route file in angularjs and have multiple modules?

0

I'm interested in separating my app by module

app
controllers
views
diretivas
services
--modules
----principal
--------controllers
--------views
--------service
--------index.html
----cadastro
--------controllers
--------views
--------service
--------index.html
----financeiro
--------controllers
--------views
--------service
--------index.html
app.js

Being the first controller and views folder that would be the login and the template of my system But all the examples that I find, each module has its routes

How would only one file handle all routes of all modules?

    
asked by anonymous 04.07.2014 / 05:43

1 answer

1

Rod,

The user should be falling in the index.html when entering the site, right? Just call the route file inside it, for example:

HTML

<html>
  <head>
    <script src="routes.js"></script>
  </head>
  <body>
    <div ng-view></div>
</html>

routes.js

angularModule.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/principal', {
        templateUrl: 'principal/index.html',
        controller: 'PrincipalCtrl'
      }).
      when('/cadastro', {
        templateUrl: 'cadastro/index.html',
        controller: 'CadastroCtrl'
      }).
      when('/financeiro', {
        templateUrl: 'financeiro/index.html',
        controller: 'FinanceiroCtrl'
      }).
      otherwise({
        redirectTo: '/404'
      });
  }])

Of course you will have to adapt these routes to your need, was just an example. But finally, all the routes in a single file, which will call the respective controllers and their templates.

    
08.07.2014 / 03:27