Forward Slash in Angular Route Parameters

最后都变了- 提交于 2019-12-30 09:56:06

问题


How do I set up my routes so that my parameter can take forward slashes?

For example: myapp.com/file/rootfolder/subfolder/myfile

This doesn't work:

const SECTION_ROUTES: Routes = [
    { path: 'file/:path', component: FileStoreComponent }
];

Is having / in routing parameter values possible?

I've read about URL approaches that use URL encoding. However, I'd like my user to be able to type the URL.


回答1:


It looks like you have to escape each forward slash with a wildcard like so:

/*page

This question covers it: Angular2 RouterLink breaks routes by replacing slash with %2F

That question links to the following GitHub issue ticket that goes more in-depth: https://github.com/angular/angular/issues/8049



来源:https://stackoverflow.com/questions/44810860/forward-slash-in-angular-route-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!