azicchetti/jquerymobile-router

Router Not Triggered On Refresh

brandonhall opened this issue · 5 comments

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!

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!

Thanks Andrea, responded to your email with more information.

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.

Il 07/05/2012 07:30, Brandon Hall ha scritto:

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.

I'm really glad that you finally managed to fix everything.

In the next few days I'll add a small paragraph titled "Common mistakes"
to the router README, in order to help people overcome issues like the
one that was tormenting you.
It would be great if you could add something to it based on your experience.

Once again, thanks so much for your help.

You're welcome!

Cheers,
Andrea

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