John
John

Reputation: 634

UI-Router access the correct states when ending in '/'

I have two states in my app, one is accessed by localhost/web and the other one localhost/web/1.

They work fine if they are accessed like above, but if I add a / at the end, the first one localhost/web/ is going to access localhost/web/1 templateUrl and controller. If I add / at the end of localhost/web/1/ is going to redirect me to my default state.

I am using nginx to run my client, and I changed the location conf.

location / {
  try_files $uri /index.html;
}

The states:

.state('app.web', {
  url: '/web',
  views: {
    'container@': {
      templateUrl: '...',
      controller: '...',
    }
  }
}

.state('app.web.show', {
  url: '/:webID',
  views: {
    'container@': {
      templateUrl: '...',
      controller: '...',
    }
  }
}

Upvotes: 1

Views: 126

Answers (1)

Radim Köhler
Radim Köhler

Reputation: 123901

The UI-Router built-in solution is described here:

How to: Make a trailing slash optional for all routes

Q: How can I have my routes be activated when the url contains either a trailing slash or not?

A: Set strictMode to false in your config block:

$urlMatcherFactoryProvider.strictMode(false)

Read more details in the doc here

Upvotes: 1

Related Questions