AngularJS中UrlServiceProvider替换URL空格为短横线失效求助
Hi everyone,
I've hit a frustrating roadblock with Angular UI Router. A while back, I asked about building a custom URL type that swaps spaces for dashes (and reverses the conversion when parsing), and someone shared a fully functional example that does exactly this. But no matter what I try, I can't get the same functionality to work in my own project.
Here's the code I wrote for the custom URL type:
$urlServiceProvider.config.type('productName', { encode: function (str) { return str && str.replace(/ /g, '-'); }, decode: function (str) { return str && str.replace(/-/g, ' '); }, is: angular.isString, pattern: /[^/]+/ });
This should handle encoding spaces to dashes when generating URLs and decoding dashes back to spaces when parsing them, right? And like I mentioned, the example works flawlessly—but in my project, it's completely non-functional.
To try and narrow down the issue, I created a minimal reproduction project that's nearly identical to the working example, and uploaded it to a code hosting platform. Would anyone be willing to take a look and help me figure out why this isn't working?
内容的提问来源于stack exchange,提问作者r3plica

