Skip to content

Instantly share code, notes, and snippets.

@xiadd
Created Apr 25, 2016
Embed
What would you like to do?
html history api

pushState里的title并没有什么卵用

(function (doc, win) {

  function Router () {
    this.state = {};
    this.events = [];
  }
  //添加popstate事件
  win.addEventListener('popstate', function (e) {

  })

  Router.prototype = {
    on: function (ev, callback){
      this.events.push(ev)
    },
    set: function (url, title, callback){
      history.pushState({url: url}, title, url);
      this.state[url]=1;
    },
    check: function (url){
      return this.state.url?true:false;
    },
    delete: function (url){
      if(this.check(url)){
        delete this.state.url
      }else {
        return ;
      }
    },
    setTitle: function (title) {
      title === 'string' ? title = title : title = title.toString();
      document.title = title
    },
    refresh: function () {

    }
  }

  win.Router?win.Router:win.Router=Router;
})(document, window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment