SET001
SET001

Reputation: 11718

ui-router does not work with parameters in route

For some reason it does not work as expected for routes with parameters. It does not even render src attribute for such anchors. I made a simple plunk to demonstrate this and here is the code:

<body ng-controller="MainCtrl">
    <a ui-sref="categories/foo">category</a>
    <a ui-sref="blah">blah</a>
</body>

and routes:

$stateProvider
.state 'blah',
  url: 'blah'
.state 'categories',
  url: "categories/:name"

First work fine, second - not. Why this happening? What am I doing wrong?

Upvotes: 0

Views: 47

Answers (2)

A.B
A.B

Reputation: 20445

to Navigate to state, with params ui-sref also takes an state name as function like syntax with object of params(you want to pass to state) as an argument

So replace

<a ui-sref="categories/foo">category</a>

with

<a ui-sref="categories({name:'foo'})">category</a>

Upvotes: 2

richardtz
richardtz

Reputation: 4993

you can specify params like this (using the routes you have defined):

<a ui-sref="categories({name:'foo'})">category</a>

Upvotes: 1

Related Questions