0

thank u for looking! Here's my question.

[app.html]
...
<custom />
...
<script>
...
app.config(["$routeProvider", function ($routeProvider) {
    $routeProvider.when("/checkout", {
        templateUrl: "views/checkoutSummary.html",
    });

    $routeProvider.when("/products", {
        templateUrl: "views/productList.html"
    });

    $routeProvider.otherwise({
        templateUrl: "/views/productList.html",
    })
}])
...
</script>

The directive for "custom" is here:

<div class="navbar-right">
    <div class="navbar-text">
        <b>购物车:</b>
        {{itemCount()}} 个商品,
        {{total() | currency}}
    </div>
    <a href="#/checkout" class="btn btn-default navbar-btn">结算</a>
</div>

When I click element "a",the href in my browser is:

http://localhost:3000/app.html#!#%2Fcheckout

and the $location.hash() is /checkout

Actually, the correct href should be:

http://localhost:3000/app.html#!/checkout

or

http://localhost:3000/app.html#!%2Fcheckout

Why that the program add the "#" behind the "!"?

Tx and Happy Chinese New Year!

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Tianzhen
  • 33
  • 7
  • Possible duplicate of [URL hash-bang (#!/) prefix instead of simple hash (#/) in Angular 1.6](http://stackoverflow.com/questions/41226122/url-hash-bang-prefix-instead-of-simple-hash-in-angular-1-6) – Mistalis Jan 27 '17 at 09:20
  • Possible duplicate of [angularjs 1.6.0 (latest now) routes not working](http://stackoverflow.com/questions/41211875/angularjs-1-6-0-latest-now-routes-not-working) – georgeawg Mar 07 '17 at 02:04

1 Answers1

2

Tx! I have solve it! The reason is in version 1.6.1 the route rule has been changed. The correct way to write the url is:

href="#!/checkout"

Annother way to sovle this problem:

app.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

follow: https://github.com/angular/angular.js/commit/aa077e81129c740041438688dff2e8d20c3d7b52

Tianzhen
  • 33
  • 7