Can't understand History.js, need it simplified?

前端 未结 2 1989
失恋的感觉
失恋的感觉 2020-12-28 15:44

I\'m fairly new to programming, and I\'m making an AJAX site with the help of jQuery.

I\'ve looked around a fair bit for an AJAX history handler, and figured that Hi

相关标签:
2条回答
  • 2020-12-28 16:26

    Follow the instructions here: https://github.com/browserstate/ajaxify

    Change your links to traditional links href="#home" to href="/home" - make sure http://mywebsite.com/home works. This is all about graceful up-gradation.

    0 讨论(0)
  • 2020-12-28 16:46

    I think the "dumbed down" version you need is a router abstraction. I've written a simple one for my own purposes, called StateRouter.js. It basically takes care of directing URLs supported by your application to the correct functions, you can even define parameter parts of routes (so that e.g. the 'id' part of http://example.com/persons/id becomes a function parameter).

    This simple example code should demonstrate how it's used:

    var router = new staterouter.Router();
    // Configure routes
    router
      .route('/', getHome)
      .route('/persons', getPersons)
      .route('/persons/:id', getPerson);
    // Perform routing of the current state
    router.perform();
    // Navigate to the page of person 1
    router.navigate('/persons/1');
    

    Here's a little fiddle I've concocted in order to demonstrate its usage.

    0 讨论(0)
提交回复
热议问题