How to include a param in browsers url when using params instead of url in angular ui routing?

Vikram

I am using angular ui routing to route my modules. I know if i add something like "url: '/:campKey'," in my state then this will come in the browsers url. But instead i am using params as an array of parameters, it is not possible to have both url and params. So how do i show my campkey in the url in the browser. Thanks

.state('_.work.inside.content', {
views: {
  "": {
    controller: 'InsideContentCtrl',
    templateUrl: 'app/work/inside/content.html'
  }
},
params: ['campKey', 'from', 'to'],
data: {menu: { isHidden: true }},
resolve: {metric: ['$http', '$stateParams','appName', 'dateFilter', function($http,      $stateParams,appName, dateFilter) {
  if($stateParams.campKey) {
    return $http({
      method: 'GET', 
      url: '/-/api/' + appName + '/campaign/' + $stateParams.campKey +'/inside-content', 
      params: {from: dateFilter($stateParams.from, 'yyyy-MM-dd'), to: dateFilter($stateParams.to, 'yyyy-MM-dd')}
    }).
    success(function(resp, status) {
      return resp.results;
    })
    .error(function(err) {
      console.log(err);
      throw err;
    });
  }
}]}

});

Vikram

after searching some more i found out that instead of using 'params' as above. I can use url and get my 'campkey' in the browsers url. But i would have to remove 'params'. The changes would be as below.

.state('_.work.inside.content', {
url: '/:campKey',
views: {
  "": {
    controller: 'InsideContentCtrl',
    templateUrl: 'app/work/inside/content.html'
  }
},
data: {menu: { isHidden: true }},
resolve: {metric: ['$http', '$stateParams','appName', 'dateFilter', function($http, $stateParams,appName, dateFilter) {
  if($stateParams.campKey) {
    return $http({
    method: 'GET', 
    url: '/-/api/' + appName + '/campaign/' + $stateParams.campKey +'/inside-content', 
    params: {from: dateFilter($stateParams.from, 'yyyy-MM-dd'), to: dateFilter($stateParams.to, 'yyyy-MM-dd')}
}).
success(function(resp, status) {
  return resp.results;
})
.error(function(err) {
  console.log(err);
  throw err;
});

} }]}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular 2: how to get params from URL without using Routing?

How to get id from the url react for dispatch instead of using params?

Remove URL params on routing

Angular routing match url witch specific param

angular dupicate url when routing

how to include only part of request params into url?

How to store add params in api url using angular js

In URL `%` is replaced by `%25` when using `queryParams` while routing in Angular

How to get URL params when using Custom Document in NextJS

Routing angular 5 , passing a string on params after url

how to refresh page when routing url changes in angular

React Routing with URL Link as params

Angular UI router 0.2.18 param on root url

404 page when using params in url

Angularjs - url params: When clicked returns to angular vars in the url

How to get the angular route params values in the url?

$http requests and angular routing based on primary key or url param?

angular.js ui-route how catch route or url or params after reject?

How to specify a URL param API token, when using ClientBase?

How to get url params in NextJs like: userid/:this_is_a_param

How to change url when using include related html page

Apply angular filter on ui-router url params

Angular ui-router params if specific child-url

How to read all url params using js?

URL routing issue when using react

How to use a "complete Url" (url with params) for navigation in Angular

Angular routing using %2F in URL which is breaking routing

How to disable url changes with Angular routing

How to serialize Angular URL with auxiliary routing?