Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Router Not Triggered On Refresh #42

Closed
brandonhall opened this Issue · 5 comments

2 participants

Brandon Hall Andrea Zicchetti
Brandon Hall

Thanks for making jQM work with Backbone and your excellent addition to the community. After way too much trial and tribulation, I'm about there in getting this all to work together. Our app is very complex so there's a ton going on and I can't post much of it.

Basically, here's what's going on: I'm using single-page templates loaded with separate ids from our master routes. We have an mView.ejs file that looks like this;

<div id="<%= id %>" data-role="page">
    <%- partial('mHeader') %>
    <div data-role="content">
    </div>
</div>
<div id="solo" data-role="page">
    <%- partial('mHeader') %>
    <div data-role="content">
    </div>
</div>

That file is called with separate ids from our main backend routes file and works great for loading from one page and then navigating around. At this point, I have 3 routes setup. Two of them are absolute urls and one is hash-based. The solo above is the hash-based route.

Here's the deal I can visit the first page and the hash based url without an issue. It's important to note the URL I'm having problems with directory style i.e.: http://domain.com/directory/longassid

This works when navigating but when visiting that page directly the router is never fired. It gets there, but it doesn't recognize the regex. There's no match. Here's what the regex looks like:

new $.mobile.Router([,
    { "main" : { handler: 'main', events: 'bs' } },
    { "single\/([^?#]*)?" : { handler: 'single', events: 'bs' } },
    { "#solo[?](.*)?" : { handler: 'solo', events: 'bs' } }
], {
     // HANDLER FUNCTIONS           
     },
   { ajaxApp: true }

The single one is the route not matched on refresh. Pageinit is fired which fires our chrome and it fires the router. No issues there and it makes it all the way to the router but it isn't matched. Now, if I remove the extra stuff from after the single regex then it matches on refresh but of course no id is passed. What can I do to fix this? Is it just a regex issue? Any ideas?

Once again, I want to stress this route works fine when navigating through the app.

Thanks so much for any help!

Andrea Zicchetti
Owner

I've sent you an email with something similar to your setup.
It would be great if you could adapt it so that it shows the issue.

Thanks!

Brandon Hall

Thanks Andrea, responded to your email with more information.

Brandon Hall

Hey Andrea,

I finally found a working solution. In app-view the answer was to return immediately if there was a this._currentView was present. After adding the new route for solo and switching to the single page template with no ids, that was the missing step I mentioned in my last email.

Basically, I was forcing the app and backbone to do too much work when jQM should have handled the routing at that point.

Once again, thanks so much for your help.

Brandon Hall brandonhall closed this
Andrea Zicchetti
Owner
Brandon Hall

I'd be happy to contribute to the docs based on my experience with Backbone and jQM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.