2

Hi everyone,

I am developing a backbone app and I went through one "big" problem, I can't find any useful thinking on internet but I can't imagine I am the only one to have this problem.

I just want to use basic in-page anchor with backbone like old time.

Example : I want to my page to go down to a section when I have #section at the end of the URL. My backbone url path is site.com/#/page .... so of course site.com/#/page#section will freak out.

The only solution I found is to use push state but I don't really want to.

Is there another way to handle this behaviour ? even with another pattern or plugin .. but no push state.

Thanks very much,

jdmry

jdmry
  • 53
  • 5

1 Answers1

0

Here's how I'm doing it:

First, add Backbone.history.anchor

pathParts = Backbone.history.fragment.split('#')
Backbone.history.anchor = pathParts[1]

Then, use jQuery to scroll to the element

if (Backbone.history.anchor) {
  $('html, body').animate({
    scrollTop: $('#' + Backbone.history.anchor).offset().top - 10
  });
}
kevnk
  • 18,733
  • 3
  • 28
  • 30
  • Hey, thanks for your answer but does it mean I need to add a route for each possible anchor ?.. Like : page#section page#otherSection ... Because I also handle 404 with a *something route – jdmry Jun 12 '14 at 11:05
  • I'm not sure. My entire app runs from the *catchall route so in my case it doesn't matter. I'm not sure how it would work in your case. – kevnk Jun 12 '14 at 15:45