3

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');
    });
});
2
  • Just as a quick check, make sure that you have the angular-route.js source file; it was broken out of the core source a while ago, and routes won't work without it. Commented Jan 7, 2014 at 23:18
  • Yes, the angular-route file is loaded. Commented Jan 8, 2014 at 12:38

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

A simple mistake but it took me half an hour to find this answer which was exactly what I was missing. Thanks.
1

Your bootstrapping is wrong. It should be:

angular.bootstrap(document, ['gameApp']);

1 Comment

That's true, it solved a part of the issue. However, I still have no errors and no routes... Is there a way to check if the routes are registered in the app object ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.