0

I have this pattern in my route.js

.state('organizations', {
        url: '/companies/:options?/:keyvalue',
        templateUrl: '../app/components/organizations/organization.html',
        controller: 'OrganizationController',
        controllerAs: 'organizationsCtrl'
      })

And when I try access the URLs

/companies/
/companies/users

It works ok, but when I try

/companies/users/1

It redirects to the default view

// For any unmatched url, redirect to /dashboard
    $urlRouterProvider.otherwise('/dashboard');

Anyone can help me to see what I am doing wrong? thanks!

2
  • why the ? in the url ?
    – Weedoze
    Commented Oct 19, 2016 at 14:28
  • I use it to set that is an optional parameter, as I read on another post Commented Oct 19, 2016 at 14:31

1 Answer 1

0

I suppose that you wanted to make the options parameters optional.

Route parameters in UI Router are optional by default.

The ? suffix on route parameters simply tells UI Router where the query portion of the URL template should start

Your url should then looks like this url: '/companies/:options/:keyvalue'

This will match

/companies/
/companies/users/
/companies/users/1
5
  • Without the ? , I can not access even to /companies/ that's why I add it Commented Oct 19, 2016 at 14:32
  • If you go to /companies/users/1 that go to the otherwise state ?
    – Weedoze
    Commented Oct 19, 2016 at 14:34
  • exactly, but, if I put the ? on url: '/companies/:options?/:keyvalue' , at least goes to /companies/ /companies/users/ Commented Oct 19, 2016 at 14:37
  • Remove the ?. It does not say that the parameter is optionnal.
    – Weedoze
    Commented Oct 19, 2016 at 14:40
  • I did it, but now I can not access to /companies even, really weird Commented Oct 19, 2016 at 15:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.