2017-06-01 41 views
2

我试图用Hyperdom和Hyperdom/Router更新浏览器网址。如何使用hyperdom-router更新网址

我跟着documentations,我看到没有错误,模型属性更新但url不。我的代码看起来像这样

var h = require('hyperdom').html 
var router = require('hyperdom/router') 

function render (model) { 
    var route = router.route('/' + model.type + '/'+ model.currentBrand +'/:screen') 

    return h('div.main', 
    route({ 
     bindings:{ 
     screen: [model,'screen'] 
     }, 
     render: function() { 
     return renderMain(model) 
     } 
    }) 
) 
} 

任何帮助将不胜感激!

回答

1

有几件事情已经改变,因为Hyperdom是Plastiq,所以用hyperdom路由器,我们定义了routes()方法的对象,所以你的例子看起来有点更像是这样的:

var h = require('hyperdom').html 
var router = require('hyperdom/router') 

// this is your route definition 
var route = router.route('/:type/:brand/:screen') 

// this is your model 
var app = { 
    // the routes method returns an array 
    // of routes with bindings and render methods 
    routes: function() { 
    return [ 
     route({ 
     bindings: { 
      type: [this, 'type'] 
      brand: [this, 'currentBrand'] 
      screen: [this, 'screen'] 
     }, 
     render: function() { 
      return this.renderMain() 
     } 
     }) 
    ] 
    } 

    renderMain: function() { 
    ... 
    } 

    // this is called for all routes 
    // passing the route content as first argument 
    renderLayout: function (content) { 
    return h('div.main', content) 
    } 
} 

// mount it 
hyperdom.append(document.body, app)