[英]How to define optional parameter using UI-Router without trailing slash as well?
[英]Handle Trailing Slash in angular 4 using ng-2 ui-router-2
我是Angular 4的初學者,我對ng-2 ui-router-2中的斜杠有疑問。
當我點擊此網址時,它的效果很好
但在末尾添加/,則不會顯示頁面
我進行了搜索,但是找到了ui-router 1的解決方案,其中一種解決方案是使用
$ urlMatcherFactoryProvider.strictMode(false);
有人說要添加這樣的規則
$urlRouterProvider.rule(function($injector, $location) {
var path = $location.path();
var hasTrailingSlash = path[path.length-1] === '/';
if(hasTrailingSlash) {
//if last charcter is a slash, return the same url without the slash
var newPath = path.substr(0, path.length - 1);
return newPath;
}});
我將如何使用ng2 ui-router-2在Angular 4中做到這一點?
使用UrlService
配置。 向您的路由器配置功能添加一些代碼,以設置strictMode。
https://ui-router.github.io/ng2/docs/latest/interfaces/url.urlconfigapi.html#strictmode
export function routerConfig(router: UIRouter) {
router.urlService.config.strictMode(false);
}
@NgModule({
imports: [
UIRouterModule.forRoot({ config: routerConfig })
]
}) export class AppModule {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.