Issue with optional params on ui-router

44 views Asked by At

Here is my route :

.state('befyne.front.pages', {
    url: '/:rubrique/:sousRubrique/:pageSlug',
    templateUrl: 'components/frontoffice/pages/views/page.html',
    controller: 'FrontPageCtrl',
})

Here is a link with two params :

<a ui-sref="befyne.front.pages({rubrique : menuRb.slug, sousRubrique : menuRb2.slug, pageSlug : p2.slug})">{{p2.title}}</a>

Here is a link with just one param :

<a ui-sref="befyne.front.pages({rubrique : menuRb.slug, pageSlug : p.slug})">{{p.title}}</a>

The link with one param works otherwise the other with two params doesn't and i get this error when i click on it:

http://localhost:5000/api/pages/[object%20Object] 401 (Unauthorized)

N.B :

*I tried : squash, optional param ([:param]), regex ..but nothing has worked

*I'm working with Angular 1.3.6, ui-router 0.2.11

1

There are 1 answers

1
Ganesh Khaire On

you can use this.

 .state('befyne.front.pages', {
        url: '/pages',
        params: {
                rubrique: null,
                sousRubrique: null,
                pageSlug: null
            },
        templateUrl: 'components/frontoffice/pages/views/page.html',
        controller: 'FrontPageCtrl',
    })

    <a ui-sref="befyne.front.pages({rubrique : menuRb.slug, sousRubrique : menuRb2.slug, pageSlug : p2.slug})">{{p2.title}}</a>