Shashank Vivek
Shashank Vivek

Reputation: 17514

How to hide exact url call of $routeProvider from user

Well, I've implemented angularJS and I am calling different views which is being handled by $routeProvider . The problem is that for eg:

$routeProvider.
  when('/prodDetails/:prodID', {
    templateUrl: 'templates/productDetails.html',
    controller: 'ProductController'
  }).

Now, if I click on:

<a ng-href="#prodDetails/{{ prod.id }}">View Product</a>

The browser url will show prod.id in the url tab. How can I manipulate url to hide sensitive info in it.

Upvotes: 0

Views: 570

Answers (2)

Mario Lamacchia
Mario Lamacchia

Reputation: 1723

You can use angular ui router

You can achieve that by doing:

$stateProvider.
  state('productDetail', {
    url: '/prodDetails',
    templateUrl: 'templates/productDetails.html',
    controller: 'ProductController',
    params: {
      productId: 'defaultId'
    }
  })

And in the html:

<a ui-sref="productDetail({productId: prod.id})">View Product</a>

You can have access to the productId from the controller with the service $stateParams.

EDIT:

Let's say you have a encodeId and a decodeId functions:

<a ui-sref="productDetail({productId: encodeId(prod.id)})">View Product</a>

and in the controller:

app.controller(function($stateParams) {
  var id = decodeId($stateParams.productId);
});

Upvotes: 0

Jay Patel
Jay Patel

Reputation: 5793

Use Angular UI Router. it will solve your problem without doing anything. you can then pass parameter using params object given by angular-ui-router.

Upvotes: 1

Related Questions