b.lotus
b.lotus

Reputation: 66

Angular.js route problems

I have a app.js with defined routes and a menu with ng-href fields, like:

<li>
  <a ng-href="{{user.nick}}"><i class="icon-th-large"></i>My Content Flow</a>
</li>
<li>
  <a ng-href="{{user.nick}}/movie"><i class="icon-film"></i>My Videos</a>
</li>
<li>
  <a ng-href="{{user.nick}}/blog_post"><i class="icon-pencil"></i> My Blogs</a>
 </li>
<li>

Route Provider config:

$routeProvider
        .when('/:searchType?/:searchValue?', {
            templateUrl: 'partials/name/flow/',
            controller: 'FlowCtrl'
        })
.otherwise({
    redirectTo: '/'
});

$locationProvider.html5Mode(true);

:searchType is the user nick

:searchValue is gallery, movie or blog_post

Sometimes, when I click on the link, angular.js refresh the whole page, doing an application re-initialization. Can I avoid the whole refresh without using special directives and why sometimes works and sometimes doesn't?

If you want to see the demo go on filmannex with:

email: [email protected]

password: testing

Thanks

Upvotes: 0

Views: 78

Answers (1)

craigb
craigb

Reputation: 16907

You should have a leading / before your ng-href values. I suspect they are interpreted as relative URLs so it is probably falling into the otherwise() bucket and redirecting to /

<a ng-href="/{{user.nick}}">user</a>
<a ng-href="/{{user.nick}}/movies">movies</a>

Upvotes: 1

Related Questions