Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS and Angular routes

I'm having an issue with the routes of Angular. I don't have any errors, the routes are simply not working.

The following code is the simplest example where I redirect any route to #/reports. I checked the following piece of code without RequireJS and it works. I'm now wondering if I forgot something about the interactions between requireJS and Angular ?

I bootstrap Angular (and I get the bootstrap log), is there a link with my issue ?

Here is the code :

define([
    'jquery',
    "angular",
    "angular-route"
],        
function($, angular, AngularRoutes){ 

    var gameApp = angular.module('gameApp', [
        'ngRoute'
    ]);

    gameApp.config(['$routeProvider',
        function($routeProvider) {
            $routeProvider.
                otherwise({
                    redirectTo: '/reports'
                });
        }
    ]);


    angular.element().ready(function() {
        angular.bootstrap(document, [gameApp['name']]);
        console.log('Angular Bootstrapped');
    });
});
like image 210
Raphaël Boucher Avatar asked Apr 17 '26 22:04

Raphaël Boucher


2 Answers

I needed to have the <div data-ng-view></div> tag in my HTML, otherwise routing doesn't work.

like image 187
Raphaël Boucher Avatar answered Apr 19 '26 11:04

Raphaël Boucher


Your bootstrapping is wrong. It should be:

angular.bootstrap(document, ['gameApp']);
like image 28
Stewie Avatar answered Apr 19 '26 10:04

Stewie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!