I have been unable to find any articles on Backbone.Marionette using pushstate withOUT Node.js, or grunt, or require where a serious discussion is made about URL handeling. A user should be able to send a link to an internal page to her grandmother and have the link work, for example. The pushstate functionality seems uniquely ill-suited to the real world. Can someone comment and perhaps provide some links to serious articles on the subject?
Asked
Active
Viewed 1,767 times
2
-
How to do (step 2) that on node: [http://stackoverflow.com/questions/16579404/url-rewriting-with-expressjs][1] [1]: http://stackoverflow.com/questions/16579404/url-rewriting-with-expressjs – Eduardo Diego Dec 20 '14 at 19:57
1 Answers
3
Generally speaking, there's really just 2 things you need to do...
- Tell Backbone to use pushstate by calling
Backbone.history.start({ pushState: true });
. You may also need to add something likeroot: 'myApp'
to that parameter if your Marionette app is served from http://example.com/myApp instead of directly on http://example.com. - Configure your web server so that no matter what URL the user requests, the same content (your Marionette app) is returned (without doing a redirect).
The catch is that #2 is implemented differently depending on what type of web server you are using. And you haven't told us what stack you're on. In ASP.NET, for example, this can be handled by setting up a 'catch all' route by adding something like this to your RouteConfig.cs file:
// all requests (except those explicitly handled by another route)
// go to HomeController.Index and then the Backbone router examines
// the URL client-side to determine client-side what to do
routes.MapRoute(
name: "Default",
url: "{*clientRoute}", // this is wildcard which captures the entire URL
defaults: new { controller = "Home", action = "Index" }
);
Other web server stacks will have different ways of achieving the same type of thing.

Robert Levy
- 28,747
- 6
- 62
- 94
-
I kinda suspected this was the way. Thank you for this confirmation. – Joel Ephroni Mar 08 '13 at 16:19
-
Afraid not but if you post that as a specific question im sure somebody can hook you up – Robert Levy Mar 09 '13 at 05:04