2017-06-01 43 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)