I have sammy.js running in webapp, performing the routing functionality to
determine the state of the app based on the url. I'm currently trying to
redirect routes that are missing the trailing slash (for example
/#/stop/1/100032). I would like to redirect all such pages missing the
trailing slash, to the page with the trailing slash.
To complicate things, I would also like to have an error page in the case
that there is no such route.
This is what I have so far.
self.router = Sammy(function () {
> this.get('/#/stop/:agency_id/:stop_id/', function () {
> app.page.state('bus');
> app.stop.setCurrentById(this.params['agency_id'], this.params[
> 'stop_id']);
> mixpanel.track('stop page load', {
> 'route': '/#/stop/' + this.params['agency_id'] + '/' + this
> .params['stop_id'] + '/',
> });
> });
> this.get('/stop/:agency_id/:stop_id/', function () {
> app.page.state('bus');
> app.stop.setCurrentById(this.params['agency_id'], this.params[
> 'stop_id']);
> mixpanel.track('stop page load', {
> 'route': '/stop/' + this.params['agency_id'] + '/' + this
> .params['stop_id'] + '/',
> });
> });
> this.get('/support/', function () {
> app.page.state('support');
> app.page.header('Support BusTimes.ca');
> app.page.title('Support BusTimes.ca');
> app.page.message('');
> mixpanel.track('support page load');
});
> this.get('/identify/', function () {
> app.page.state('identify');
> app.page.header('Identify for BusTimes.ca');
> app.page.title('Identify for BusTimes.ca');
> app.page.message('');
> mixpanel.track('identify page load');
> });
> this.get('/', function() {
> app.page.state('bus');
> app.stop.findNearest();
> mixpanel.track('main page load');
> });
> this.get('/(.*[^\/])', function () {
> this.redirect('/', this.param['splat'], '/');
> });
> });
> self.router.error = function (message, error) {
> app.page.state('error');
> app.page.header("Unable to find your page");
> app.page.message("The page you've requested could not be found.<br
> /><a href=\"/\">Click here</a> to return to the main page.");
> }
> self.run = function () {
> self.router.run();
> }
So everything seems to work so far except for the redirecting of the
pages missing the trailing slash. For some reason they just end up at the
error page
Any help would be greatly appreciated.