From 18683f9ca87d7349d58bf7bdd75430a253217ebc Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 18 Aug 2016 10:57:59 +0200 Subject: [PATCH] Fix backbone router for URLs with trailing slashes --- app/assets/javascripts/app/router.js | 57 ++++++++++++++-------------- spec/javascripts/app/router_spec.js | 5 +++ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 5f8a3cc96..d7bb3042c 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,35 +2,34 @@ app.Router = Backbone.Router.extend({ routes: { - "activity": "stream", - "admin/pods": "adminPods", - "admins/dashboard": "adminDashboard", - "aspects": "aspects", - "commented": "stream", - "community_spotlight": "spotlight", - "contacts": "contacts", - "conversations": "conversations", - "followed_tags": "followed_tags", - "getting_started": "gettingStarted", - "help": "help", - "help/": "help", - "help/:section": "help", - "liked": "stream", - "mentions": "stream", - "notifications": "notifications", - "p/:id": "singlePost", - "people": "pageWithAspectMembershipDropdowns", - "people/:id": "profile", - "people/:id/contacts": "profile", - "people/:id/photos": "photos", - "posts/:id": "singlePost", - "profile/edit": "settings", - "public": "stream", - "stream": "stream", - "tags/:name": "followed_tags", - "u/:name": "profile", - "user/edit": "settings", - "users/sign_up": "registration" + "activity(/)": "stream", + "admin/pods(/)": "adminPods", + "admins/dashboard(/)": "adminDashboard", + "aspects(/)": "aspects", + "commented(/)": "stream", + "community_spotlight(/)": "spotlight", + "contacts(/)": "contacts", + "conversations(/)": "conversations", + "followed_tags(/)": "followed_tags", + "getting_started(/)": "gettingStarted", + "help(/)": "help", + "help/:section(/)": "help", + "liked(/)": "stream", + "mentions(/)": "stream", + "notifications(/)": "notifications", + "p/:id(/)": "singlePost", + "people(/)": "pageWithAspectMembershipDropdowns", + "people/:id(/)": "profile", + "people/:id/contacts(/)": "profile", + "people/:id/photos(/)": "photos", + "posts/:id(/)": "singlePost", + "profile/edit(/)": "settings", + "public(/)": "stream", + "stream(/)": "stream", + "tags/:name(/)": "followed_tags", + "u/:name(/)": "profile", + "user/edit(/)": "settings", + "users/sign_up(/)": "registration" }, initialize: function() { diff --git a/spec/javascripts/app/router_spec.js b/spec/javascripts/app/router_spec.js index a290c887e..3b185a5f2 100644 --- a/spec/javascripts/app/router_spec.js +++ b/spec/javascripts/app/router_spec.js @@ -93,6 +93,11 @@ describe('app.Router', function () { app.router.navigate("/getting_started", {trigger: true}); expect(app.page.$el.selector).toEqual("#hello-there"); }); + + it("renders app.pages.GettingStarted when the URL has a trailing slash", function() { + app.router.navigate("/getting_started/", {trigger: true}); + expect(app.page.$el.selector).toEqual("#hello-there"); + }); }); describe("_initializeStreamView", function() {