Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS routes with parameters in path not loading in HTML5 mode when going directly to URLs
    primarykey
    data
    text
    <p>I have a few routes specified:</p> <pre><code>app.config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) { $routeProvider. when("/", { templateUrl: "/ajax/home.html", controller: "HomeController" }). when("/test/:id", { templateUrl: "/ajax/test.html", controller: "TestController", resolve: { data: function ($q, $http, $route) { var deferred = $q.defer(); var params = $route.current.params; $http({method: "GET", url: "/api/test/" + params.id + ".json"}) .success(function(data) { deferred.resolve(data) }) .error(function(data){ deferred.reject(); }); return deferred.promise; } } }); $locationProvider.html5Mode(true); }]); </code></pre> <p>When there is a link on another route leading to <code>/test/x</code>, it works fine. It also works fine when not in HTML5 mode. However, when you navigate directly to <code>/test/x</code> in HTML5 mode, the route doesn't load and none of the stuff in resolve is executed.</p> <p>I've looked through much of the AngularJS documentation and still can't figure this out. plz :(</p> <p>Edit: I've done more testing, and this is only for routes that have a slash in them. It doesn't seem to matter if there is a parameter (like <code>:id</code>) in it or not. Going to <code>/hello</code> (if that route is defined) works for all cases in both HTML5 and non-HTML5 mode. Going to something like <code>/hello/world</code> always works in non-HTML5 mode and works in HTML5 mode when the route is changed from another route by clicking a link. Refreshing when on <code>/hello/world</code>, going to the address bar and pressing enter or clicking a link pointing to it from another website causes it to reload the index page but not the actual route.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload