8000 Params not yet available in 'pushState' and 'render' event handlers · Issue #463 · choojs/choo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Params not yet available in 'pushState' and 'render' event handlers  #463
Closed
@brechtcs

Description

@brechtcs

Expected behavior

When handling a 'pushState' event, the resolved state.params should already be available upon calling the event handler.

Actual behavior

Resolved params are only added to state during render.

Steps to reproduce behavior

To reproduce, click on the link to 'some page' in this example app:

var choo = require('choo')
var html = require('choo/html')

var app = choo()

app.route('/', function () {
  return html`
    <body>
      <a href="/somepage">some page</a>
    </body>
  `
})

app.route('/*', function (state) {
  return html`
    <body>
      page: ${state.params.wildcard} <!-- correctly renders 'somepage' -->
    </body>
  `
})

app.use(function (state, bus) {
  bus.on('pushState', function () {
    console.log(state.params.wildcard) // logs undefined
  })

  bus.on('render', function () {
    console.log(state.params.wildcard) // logs undefined
  })
})

app.mount('body')

This is a problem for my specific use case, because in the 'pushState' (or 'render') event handler, I want to fetch some data based on the page param, and fill out the page based on the response.

As an aside, I do want to mention that working with choo v5 has been a real joy so far. You absolutely nailed it with the new stripped-down API for app.use!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0