UI-路由器以“/”结尾时访问正确的状态

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

我的应用程序有两种状态,一种被 localhost/web 访问,另一种被 localhost/web/1.

访问

如果像上面那样访问它们,它们工作正常,但如果我在末尾添加一个 /,第一个 localhost/web/ 将访问 localhost/web/1 templateUrl 和控制器。如果我在 localhost/web/1/ 的末尾添加 / 会将我重定向到我的默认状态。

我正在使用 nginx 到 运行 我的客户端,我更改了位置配置。

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

州:

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

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

此处描述了 UI-Router 内置解决方案:

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)

阅读 doc here

中的更多详细信息