Skip to content
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

create location object to handle URL #5

Open
Takazudo opened this issue Apr 10, 2012 · 2 comments
Open

create location object to handle URL #5

Takazudo opened this issue Apr 10, 2012 · 2 comments

Comments

@Takazudo
Copy link
Owner

Let's say you create web app. It's like diary or something which based on year-month-day data from URL.

http://example.com/2012/12/27/

Then, I want API like this.

router.route([
    path: /\/([^\/]+)\/([^\/]+)\/([^\/]+)\//, /* ex: /year/month/day/ */
    avoidpagefetch: true,
    insteadpagefetch: function(page, path){
        $('#main').html(pageframehtml);
        var year = path.matchedPathFragments[0];
        var month = path.matchedPathFragments[1];
        var day = path.matchedPathFragments[2];
        callMyApi(year, month, day).done(function(data){
            updateSomethingFromData(data);
            page.trigger('pageready');
        });
    }
]);

I may implement a thing like this.

@Takazudo
Copy link
Owner Author

var loading = new Loading();
router.route([
  path: /\/([^\/]+)\/([^\/]+)\/([^\/]+)\//, /* ex: /year/month/day/ */
  skippagefetch: true,
  pageready: function(location){
    loading.show();
    console.log(location.rip(0)); // year
    console.log(location.rip(1)); // month
    console.log(location.rip(2)); // day
    callAjaxApiOrSomething(year, month, day).done(function(data){
      renderViewOrSometing(data).done(function(){
        loading.hide();
      });
    });
  });
]);

This may be enough because non-history-supported browser can handle only pageready. All we need here seems the location object above.

@Takazudo Takazudo mentioned this issue Apr 14, 2012
@Takazudo
Copy link
Owner Author

Location object needs to handle get values like below, too.

http://example.com/foobar/?foo=bar

I need to parse the value like above in URL routing.
Davis.js handles this. But we need to handle it even if the user can't use history.pushState.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant