Re: [angular.js] Re: $locationProvider in HTML5 mode with non-provided routes

8,359 views
Skip to first unread message

AJ Mercer

unread,
Jun 25, 2012, 6:24:47 AM6/25/12
to ang...@googlegroups.com
does that mean

angular.module('project', [], function($routeProvider, $locationProvider) {
  $routeProvider.
  when(
      ...)
.otherwise({redirectTo:'/'});

no long redirects??


Does anyone have the rewrite rule for .htaccess so angularJS can handle urls like /contact


On 25 June 2012 04:42, Robert Damphousse <rjda...@gmail.com> wrote:
I upgraded from rc8 to 1.0.0 and the problem has gone away, routes that are not specified by the routeProvider will trigger a page load


On Saturday, June 23, 2012 1:42:12 PM UTC-7, Andy Joslin wrote:
Just a guess... but try an empty .otherwise()?

angular
        .module('admin.Rooms', [])
        .config(['$routeProvider','$locationProvider',function ($routeProvider,$locationProvider) {
            $locationProvider.html5Mode(true)
            $routeProvider
                .when('/admin/rooms/:room_id', {template: '/lib/adminRooms/views/room'})
                .when('/admin/rooms', {template: '/lib/adminRooms/views/roomlist'})
 
                                .otherwise({});
        }])

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/flEYO-s5zi0J.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.



--

AJ Mercer
<webonix:net strength="Industrial" /> | <webonix:org community="Open" />
http://twitter.com/webonix

Jeremy Orlow

unread,
Mar 12, 2013, 9:32:45 PM3/12/13
to ang...@googlegroups.com
I'm hitting this using 1.0.5.  I can't believe that this is the accepted solution to the problem, but this thread is all I've found on the issue.  Is it really expected that all external links require custom code to navigate away from the app??

Thanks,
Jeremy

On Wednesday, June 27, 2012 5:07:55 PM UTC-7, Thomas Bunting wrote:
I've still got this problem using angular 1.0.1.

Unspecified routes are not causing a page load.

Can anyone help?

Peter Bacon Darwin

unread,
Mar 17, 2013, 7:57:06 AM3/17/13
to ang...@googlegroups.com

Can you give an example? If you put http://... In your urls it should trigger a reload.

... sent from my tablet

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.

Max Favilli

unread,
Mar 29, 2013, 10:15:27 AM3/29/13
to ang...@googlegroups.com
I have the same problem and I described my solution here: http://stackoverflow.com/questions/15704720/angular-routing-something-weird-happening

But it's not elegant and it lead me to another problem that I have not been able to solve yet.

For the ones too lazy to follow the link to stackoverflow what I did is:

var app = angular.module('app', []);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
  $routeProvider.
    when('/pneumatici/:chunka', {}).
    when('/pneumatici/:chunka/:chunkb', {});

  $locationProvider.html5Mode(true);
}]);
Plus:
app.controller('appCtrl', ['$scope', '$route', '$routeParams', '$location', function ($scope, $route, $routeParams, $location) {
  $scope.$on('$routeChangeSuccess', function (current,previous) {
    if (!($location.path().indexOf('/pneumatici') === -1)) {
      $scope.chunka = $route.current.params.chunka; $scope.chunkb = $route.current.params.chunkb;

      /** do my stuff with chunka and chunkb **/

    } else {
      window.location.href = $location.path();
    }
  });
I tried using .otherwise but I could not figure out how to do make it work.

The problem I have with this solution (just in case someone comes up with a solution) is that for these links which trigger a page load (like just '/privacy.html') once I follow them clicking on them the page loads correctly and I do see '/privacy.html' content, but unfortunately once there if I click the back button I can see the url of the browser changing to (let's say) /pneumatici/foo/bar but no page load is triggered. And in the privacy.html page I have no angular routing defined, there's no .config no .when; there's an anagular app defined, with a controller, but no injection of '$routeProvider' anywhere, no definition of any route.

Max Favilli

unread,
Mar 29, 2013, 11:45:25 AM3/29/13
to ang...@googlegroups.com
I found something interesting I didn't know; any 'A' element with target set to "_self" will be ignored by angular routing. So if I do the following:

angular.element("a").prop("target", "_self");

I solve my issue.

Still if I look at this strategy as a whole doesn't sound very elegant to me and I would love to improve it. What I don't like is since I am defining the route in .config I should be able to tell angular to skip any url which do not match the format/path I defined there.

But I don't know if that is doable or not, does anyone know out there?
Reply all
Reply to author
Forward
0 new messages