I'm trying to get set up an angularJS app with jQuery and I'm using the angular routing system for urls doing something like the following:
var app = angular.module('app', []);
app.config(function($routeProvider) {
$routeProvider.when('/start_page', {
templateUrl: 'path/to/template',
controller: 'StartPageController'
});
$routeProvider.when('/container/:container/thing/:thing', {
templateUrl: 'path/to/template',
controller: 'ThingsInContainersController'
});
$routeProvider.otherwise({ redirectTo: '/start_page' });
})
I can navigate to the start page which has an interface that allows me to select a container_id and a thing_id and then sends me to the route for the container and thing which all works perfectly. The problem is that if I refresh the container thing page then I get the following error:
Uncaught Error: Syntax error, unrecognized expression: [href=#container/1/thing/2]
which seems to be a jQuery error from the stack trace. The trace doesn't mention my code at all. I tried a few things and it seems that whenever I enter a url with more than one / after the # I get the error instead of being properly redirected to the start page. My solution for now was to use -s instead of /s as a url delimiter which seems to have worked but I suspect there is actually a correct way of doing this and I'm wondering what it is.
My current solution:
var app = angular.module('app', []);
app.config(function($routeProvider) {
$routeProvider.when('/start_page', {
templateUrl: 'path/to/template',
controller: 'StartPageController'
});
$routeProvider.when('/container-:container-thing-:thing', {
templateUrl: 'path/to/template',
controller: 'ThingsInContainersController'
});
$routeProvider.otherwise({ redirectTo: '/start_page' });
})
/mycontainerthingurl/:containerID/:thingID