URL 中的参数使用 Angular 的 UI-路由器,问题与 .otherwise
Parameters in URL using Angular's UI-Router, issue with .otherwise
我想在我的页面上搜索。实际上,我的代码是
$stateProvider
.state('aaa', {
url: '/aaa',
templateUrl: 'client/parties/views/aaa.ng.html',
controller: 'Aaa'
})
$urlRouterProvider.otherwise("/default");
现在,我想在我的页面上搜索,但参数必须与 URL 一起使用。
当我有 $urlRouterProvider.otherwise 时如何使用参数?
实际上,URL 中 /aaa/ 之后的所有内容都会导致重定向到 /default.
重要的是:我有20多个参数,但是没有选择的时候,我不想通过URL传递。这很重要,因为我认为我不能做类似 url: '/details/:param1:param2:param3:param4',
你能帮帮我吗?
查看 documentation 的 ui-router,似乎不可能在状态路由上至少定义一个参数的情况下不重定向它。
为了完成你想要的,我认为最好的方法是使用某种类型的 catch all 参数。要么是限制深度链接,要么是减少参数数量并手动定义它。
- 定义一个 catch all 参数,如下所示。在这种情况下,如果“/files/”之后没有任何内容,则参数是路径重定向将不会发生:
'/files/{path:.*}' - Matches any URL starting with '/files/' and captures the rest of the path into the parameter 'path'.
'/files/*path' - Ditto. Special syntax for catch all.
- 在新路由上定义一个参数,然后在控制器中将一个参数拆分成多个参数。
我想在我的页面上搜索。实际上,我的代码是
$stateProvider
.state('aaa', {
url: '/aaa',
templateUrl: 'client/parties/views/aaa.ng.html',
controller: 'Aaa'
})
$urlRouterProvider.otherwise("/default");
现在,我想在我的页面上搜索,但参数必须与 URL 一起使用。 当我有 $urlRouterProvider.otherwise 时如何使用参数? 实际上,URL 中 /aaa/ 之后的所有内容都会导致重定向到 /default.
重要的是:我有20多个参数,但是没有选择的时候,我不想通过URL传递。这很重要,因为我认为我不能做类似 url: '/details/:param1:param2:param3:param4',
你能帮帮我吗?
查看 documentation 的 ui-router,似乎不可能在状态路由上至少定义一个参数的情况下不重定向它。
为了完成你想要的,我认为最好的方法是使用某种类型的 catch all 参数。要么是限制深度链接,要么是减少参数数量并手动定义它。
- 定义一个 catch all 参数,如下所示。在这种情况下,如果“/files/”之后没有任何内容,则参数是路径重定向将不会发生:
'/files/{path:.*}' - Matches any URL starting with '/files/' and captures the rest of the path into the parameter 'path'.
'/files/*path' - Ditto. Special syntax for catch all. - 在新路由上定义一个参数,然后在控制器中将一个参数拆分成多个参数。