choojs / choo

:steam_locomotive::train: - sturdy 4kb frontend framework
https://choo.io/
MIT License
6.78k stars 595 forks source link

Multi-pages with layout? #92

Closed crapthings closed 8 years ago

crapthings commented 8 years ago

how to replace main content while navigate through router

yoshuawuyts commented 8 years ago

You can nest functions like this:

const app = choo()

app.router((route) => [
  route('/foo', common(fooView)),
  route('/bar', common(barView))
])

function common (mainView) {
  return function (params, state, send) {
    return html`
      <aside>sidebar content</aside>
      <main>${mainView(params, state, send)}</main>
    `
  }
}

function fooView (params, state, send) {
  return html`<div>foo</div>`
}

function barView (params, state, send) {
  return html`<div>bar</div>`
}

The morphdom algorithm should do the work to ensure these transitions happen as smooth as possible. Does this answer your question?

hew commented 8 years ago

@yoshuawuyts I think that should be view`` instead ofhtml``.

yoshuawuyts commented 8 years ago

@hew oh, I nowadays usually do const html = choo.view to have parity with const css = require('sheetify') from sheetify

Using css and html as var names makes stuff pretty straight forward I've found :sparkles:

hew commented 8 years ago

@yoshuawuyts That makes sense. 👍🏽

yoshuawuyts commented 8 years ago

I'm going to assume this solves your issue. Thanks for opening! :sparkles: