vikrant
vikrant

Reputation: 141

ui router dynamic URL issue - url: '/:id/page1' not working

How to create dynamic route when using ui router,

if we define:

$stateProvider.state('page1', {
      url: '/page1/:id',
      views:{}
}

It works fine,

But if we try to add dynamic id first and then page name then it gives error,

ERROR:

$stateProvider.state('page1', {
      url: '/:id/page1',
      views:{}
}

How to resolve this issue, can anyone help me into this?

Upvotes: 1

Views: 139

Answers (1)

thepio
thepio

Reputation: 6263

Ok so based on your comment you should use something like this:

$stateProvider
  .state('page1', {
  url: '/:id/page1'
});

The part above was just fine. But in your link you should use something like this:

<a ui-sref="page1({id: '1234'})">page1</a>

You can also set a variable to the ui-sref like:

<a ui-sref="page1({id: page.id})">page1</a>

Upvotes: 1

Related Questions