Petran
Petran

Reputation: 8047

Angularjs redirect with search parameters

I use angularjs 1.6 on my routes I have the following

  when('/myview', {
    templateUrl: 'mc/templates/myview.html',
    controller: 'myviewController'
  }).
  otherwise({
    redirectTo: '/defaultView'
  });

When I access myview with search parameters it loads the myview view

/myview?foo=bar

When I try to redirect to this view though

$location.path(' /myview?foo=bar');

Does not work and loads the defaultView

How can I redirect on a view with search parameters ?

Upvotes: 0

Views: 35

Answers (2)

Abdul Rafay
Abdul Rafay

Reputation: 807

try this

$location.path('/myview').search('foo', 'bar')

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222522

You should use

 $state.go("myview", { foo: 'bar' });

or with location use .search

$location.path('/myview').search('foo', 'bar')

Upvotes: 1

Related Questions