Skip to content

How to run code after a RouteResolver has finished rendering? #2571

Closed
@sheffieldnikki

Description

@sheffieldnikki

Mithril version: 2.0.4

In the docs (https://mithril.js.org/route.html#preloading-data), a RouteResolver object is used for preloading data with onmatch and then the vnode is returned by the render hook.

I'd like to run code after the rendering has completed, which for a component could be done from the oncreate hook, but RouteResolver objects don't have lifecycle methods? Apologies for the noob question, but I'm just getting started using Mithril. Thanks!

Code

var state = {
    users: [],
    loadUsers: function() {
        return m.request("/api/v1/users").then(function(users) {
            state.users = users
        })
    }
}

m.route(document.body, "/user/list", {
    "/user/list": {
        onmatch: state.loadUsers,
        render: function() {
            return state.users.map(function(user) {
                return m("div", user.id)
            })
        }
    },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: QuestionFor issues that are purely questions about Mithril, not necessarily bug reports or suggestions

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions