Closed
Description
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
!