My URLs on an AngularJS project have changed from localhost:3000/admin#/
to localhost:3000/admin#!/
since the last time I worked on my project...
Nothing found on the web, does someone know what this is ?
My URLs on an AngularJS project have changed from localhost:3000/admin#/
to localhost:3000/admin#!/
since the last time I worked on my project...
Nothing found on the web, does someone know what this is ?
It is new from AngularJS 1.6, which added a new hash prefix.
Due to aa077e8, the default hash-prefix used for
$location
hash-bang URLs has changed from the empty string (''
) to the bang ('!'
). If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a!
prefix. For example, rather thanmydomain.com/#/a/b/c
the URL will becomemydomain.com/#!/a/b/c
.
Source here for more information.
If you want to remove this prefix, add this code to your config:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
Everyone is proposing to remove the prefix, but you could also simply add a !
to client-side URLs (if not using HTML5 mode, which you probably do if you're here).
So in your client-side files, update URLS like this:
#/foo/bar
> #!/foo/bar
In Angular 1.6.0, the default hashPrefix has been changed to !
.
See the related commit and the changelog entry.
In my situation, angular 1.6 added a hashtag in this form: http://localhost:52245/#/callback#code=BD55C7FD4F129A9CAC1506E225EF9149
But I needed it in this form: http://localhost:52245/callback#code=BD55C7FD4F129A9CAC1506E225EF9149
I spent some days until find the solution. So added this configuration in the frondEnd web.config, in <system.webServer> section:
<rewrite>
<rules>
<rule name="angular cli routes" stopProcessing="true">
<match url=".*"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/"/>
</rule>
</rules>
</rewrite>
After that, all work ok
#
to declare route parameters looks a bit awkward. You might want to use a more common route format like /callback/BD55C7FD4F129A9CAC1506E225EF9149
or /callback?code=BD55C7FD4F129A9CAC1506E225EF9149
Also here's a great SO answer on different ways to pass parameters into AngularJS routes: https://mcmap.net/q/77309/-how-to-pass-parameters-using-ui-sref-in-ui-router-to-the-controller –
Microstructure © 2022 - 2024 — McMap. All rights reserved.