uksz
uksz

Reputation: 18719

Linking in AngularJS - $routeProvider

I have an issue with $routeProvider.

I have 2 views. First view is with a list of users. Second one, is the profile of a user.

In my first view, I have specified the link:

<a ng-href="#/view2/{{user.login}}">{{user.login}}</a>

In the js file of the view2, I have specified:

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/view2/:user', {
    templateUrl: 'view2/view2.html',
    controller: 'View2Ctrl'
  });
}])

And now, whenever I try to click on the link, it just changes the url to the following:

path-to-the-file:/index.html#/view2/blabla where blabla is a user.login

So how can I make it work?

Thanks!!

Upvotes: 1

Views: 47

Answers (1)

imriqwe
imriqwe

Reputation: 1455

After using both ngRoute and ui-router, I would definitely use ui-router for routing purposes (https://github.com/angular-ui/ui-router).

ui-router exposes a much broader API for daily tasks such as linking. For example, you can use a custom directive called ui-sref:

<a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>

Therefore you don't have to assemble links by yourself, the framework does it for you.

Upvotes: 1

Related Questions