-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subroute fails if called before Backbone.history has been started #3
Comments
I have the same problem. Did you fix the problem? |
I have changed And now It works |
Hi, I had the same issue and solved it by creating the subrouter in a handler of the main router. However this introduces a new problem. When I take a look at the Backbone.history object, I notice that when I reload the page with the url of any of the subroutes (except the empty subroute), that the handlers for the subroutes are no longer there! For example in the main router: getRecords: function () { In the subrouter: When I go to localhost:8080/#records but when I go to localhost:8080/#records/1 again reloading localhost:8080/#records does not cause any problems Going straight to localhost:8080/#records/1 also does not trigger the subrouts (handlers not there) which probably comes down to the same thing as reloading. Any suggestions? |
Hello again, It looks like I managed to get it sorted. In the piece of code that get called before anything else I have added: app.router = new Router(); // this is the main router I'll let you know if I run into any problems. |
I don't use lazy loading and I couldn't get it working until I commented these lines:
I initialize subrouters in main router |
I do lazy load my sub-routers and I discovered that having a catch-all in my sub-routers fixes the issue for me. routes: { |
Hi all, The procedure I've been using is:
I, too, have noticed that #3 must come after #2. In my workflow this isn't a problem. Let me know if there are specific use cases that make this workflow problematic for anyone, and if possible include some code samples. Also I just checked in a Jasmine test suite, so in the future it would be great to see a failing test spec for any reported issues. If I don't hear back on this issue in a couple weeks, I'll go ahead and close it with the above steps as the recommended course of action. |
Thanks Robin. I have considered creating an extension of Backbone Router Just noticed that your comment appears to have been deleted from the issues Thanks, On Tue, Nov 13, 2012 at 2:19 AM, Robin Wenglewski
|
i just tried it myself and getting the same issue. too deep and too tight so cant put more details right now. but wudnt it be a good idea to somehow check if the history is not started and start it in the constructor of subroute? |
I've noticed a little bit of strange behavior that I believe is related to this issue. If I load a sub route i.e. 'route/sub' right off the bat, I notice that the subrouter does not get called. However, if I add an initialize onto my subrouter and do some kind of action there like a simple console.log, it DOES work.
Any idea why that might happen? |
I tried initializing a subroute within the
initialize
of my main router, and this works fine if I start at the root and browse to a route covered by my subroute, but doesn't work if I load a subroute-related path initially. (So, if my subroute covers '#books' and I start at www.books.com and navigate to www.books.com/#books everything is fine; but if I load up www.books.com/#books in my browser, it throws an exception.) The reason for this is thatBackbone.history.loadUrl
referencesoptions.root
which won't exist until after Backbone.history.start has been called. And I can't start Backbone.history before I've created my router either. This is with Backbone v0.9.2.Your initial approach was to create the subroute in a handler of the main router, but I'm getting a stack overflow with that approach in IE (at least IE8, I think IE9 as well). I'll create a separate issue for that.
The text was updated successfully, but these errors were encountered: