Skip to content

Instantly share code, notes, and snippets.

@busticated
Last active December 19, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save busticated/5961163 to your computer and use it in GitHub Desktop.
Save busticated/5961163 to your computer and use it in GitHub Desktop.
angularjs routes... how do they work?
app.config(function($routeProvider, $locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider
.when('/', {
templateUrl: '/html/home.html',
controller: 'HomeCtrl'
})
.when('/templates', {
templateUrl: '/html/tmpl.list.html',
controller: 'TmplCtrl'
})
.when('/templates/edit/:id', {
templateUrl: '/html/tmpl.edit.html',
controller: 'TmplCtrl'
})
.otherwise({
template: 'whoopsie! we don\'t have one of those'
});
});
/*
two issues:
1. visiting "/templates" works fine*... but visiting "/templates/" causes the "/" route to be invoked
+ well, it loads the home.html into ng-view... but clicking on a link to "/templates" has no effect
(i would expect the "/templates" route to load when clicking that link but the view does not change)
+ UPDATE: in fact, visiting "/templates/angularjs/wat/r/u/doing/this/is/weird/templates" also gets me
to the "/templates" route(!)
2. clicking from "/" in to the "/templates/edit/1" route works fine*... but then refreshing the browser invokes .otherwise()
+ basically, I cannot enter "mysite.com/templates/edit/1" into the browser's address bar and have my view load properly
+ UPDATE: because angular thinks i'm visting "/1" which doesn't exist... only the last "/<segment>" is used
* view loads, data loads and displays
NOTE: server is configured to return layout.html (app chrome) for any non-static file serving route.
so, for both scenarios above my app chrome and scripts and images load fine... it just appears that angular isn't
handling the initial route
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment