1

I was developing a sample application to learn AngularJs.

There are three links that show up three different templates in the ng-view .

main.html has the three links.

$routeProvider.when('/add/:num',{
    templateUrl: 'addition.html',
    controller: 'addCtrl',
    requireLogin : true
    })
    .when('/multiply/:num/',{
    templateUrl: 'multiplication.html',
    controller: 'multiplyCtrl',
    requireLogin : true
    })
    .when('/filter',{
        templateUrl: 'filter.html',
        controller: 'filterCtrl',
        requireLogin : true
    })
    .when('/main',{
        templateUrl: 'main.html',
        requireLogin : false

    });

here is the anchor:

<a href="add/5">

It works fine. But when i try to open the link in a new Tab, it doesn't open.

I understand that the routing is done on the client side and the server is not aware of it.

Any suggestion will be helpful.

I couldn't find any relevant answer by searching online.

Thanks.

EDIT:: server side code.

in nginx:

 location / {
    root /home/myNgApp/;
    autoindex on;
    autoindex_exact_size off;
        try_files $uri $uri/ /main.html;
      }
Learner
  • 315
  • 1
  • 5
  • 15

1 Answers1

0

AngularJS routes aren't actual html pages...

You need to have some server side routing to handle fresh page loads. We use nginx as our method of serving the URLs.

Check out this article, then you can decide what technology you would like to use.

Sten Muchow
  • 6,623
  • 4
  • 36
  • 46
  • hi, i got one more problem. the routes of the form ('/filter') is working fine. but the ones ('/add/5') or ('/filter/name') are not working as expected. any ideas on that? thanks. – Learner Apr 22 '14 at 12:10
  • if u can put more code up it would help... maybe you can try and recreate it in a plunker. But i have never used ngRouter, we opted instead for ui-router which has many more functions... – Sten Muchow Apr 22 '14 at 12:36
  • i have added the server side code for reference. hope thats helpfull. Thanks. – Learner Apr 24 '14 at 06:43