#mizchi/js_browser/history

    History API for browser navigation history manipulation.

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js_browser/history" ] }

    #Overview

    Provides bindings for the History API to manipulate browser session history.

    #Usage Example

    fn main {
    // Get history object
    let history = @history.history()

    // Navigate
    history.back()
    history.forward()
    history.go(-2) // Go back 2 pages

    // Modify history
    history.push_state(state_obj, "title", "/new-url")
    history.replace_state(state_obj, "title", "/replaced-url")

    // Get current state
    let state = history.state()

    // Get history length
    let length = history.length()
    }

    #Use Cases

    • Single Page Application (SPA) routing
    • Back/forward navigation
    • URL manipulation without page reload
    • State management across navigation

    #Reference

    History

    pub(all) struct History {
    length : Int
    state :
    Any
    ?
    scrollRestoration : String
    }

    History represents the session history https://developer.mozilla.org/en-US/docs/Web/API/History

    History::as_any

    fn History::as_any(self : History) ->
    Any

    History::back

    fn History::back(self : History) -> Unit

    Loads the previous URL in the history list https://developer.mozilla.org/en-US/docs/Web/API/History/back

    History::forward

    fn History::forward(self : History) -> Unit

    Loads the next URL in the history list https://developer.mozilla.org/en-US/docs/Web/API/History/forward

    History::go

    fn History::go(self : History, delta? : Int) -> Unit

    Loads a specific page from the session history https://developer.mozilla.org/en-US/docs/Web/API/History/go

    History::pushState

    #alias(push_state)
    fn History::pushState(self : History, state :
    Any
    , unused : String, url? : String) -> Unit

    Pushes a state onto the history stack https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

    History::replaceState

    #alias(replace_state)
    fn History::replaceState(self : History, state :
    Any
    , unused : String, url? : String) -> Unit

    Modifies the current history entry https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState

    history

    fn history() -> History

    Returns the global history object

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io