6

I'm baffled by the following: I have a simple link like this:

    <li><a href="#/foo">Foos</a></li>

but when clicking on it, the view is not updated. The URL in the browser changes, but nothing happens, and nothing gets displayed in the console. If I load the URL directly in the browser, then the correct page is loaded.

The routes look like this:

app.config(function($routeProvider, RestangularProvider) {
    $routeProvider
        .when('/index', {templateUrl: 'assets/views/index.html'})
        .when('/foos', {templateUrl: 'assets/views/list.html', controller: controllers.FooListCtrl})
        .when('/foos/create', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl})
        .when('/foos/:id/update', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl})
        .otherwise({redirectTo: '/index'});

    RestangularProvider.setBaseUrl("/admin");
});
4
  • did you try ng-href instead of href? Commented Jul 24, 2013 at 13:53
  • Yes, but without success Commented Jul 24, 2013 at 13:53
  • Any chance you can show some more of your code or even set up a plunkr where issue can be reproduced? Commented Jul 24, 2013 at 13:55
  • What do your routes look like? Commented Jul 24, 2013 at 14:37

2 Answers 2

4

Ok, so apparently, this is a known issue of sorts: when the locationProvider (i.e. $location) is injected to one controller, links cease to work globally. One workaround seems to be to rewrite the links via jQuery, and that works:

app.run(function($rootScope) {
    $('[ng-app]').on('click', 'a', function() {
        window.location.href = $(this).attr('href');
    });
});
Sign up to request clarification or add additional context in comments.

Comments

3

I have been able to resolve this issue by adding target="_self" to the link.

<li><a href="#/foo" target="_self">Foos</a></li>

I found this resolution here.

Comments

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.