Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/browser/webapi/History.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const std = @import("std");
const js = @import("../js/js.zig");

const Page = @import("../Page.zig");
const Location = @import("Location.zig");
const PopStateEvent = @import("event/PopStateEvent.zig");

const History = @This();
Expand Down Expand Up @@ -55,6 +56,10 @@ pub fn pushState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8

const json = state.toJson(arena) catch return error.DataClone;
_ = try page._session.navigation.pushEntry(url, .{ .source = .history, .value = json }, page, true);

// Update page URL and location so that location.pathname reflects the pushed state
page.url = url;
page.window._location = try Location.init(url, page);
}

pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void {
Expand All @@ -63,6 +68,10 @@ pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const

const json = state.toJson(arena) catch return error.DataClone;
_ = try page._session.navigation.replaceEntry(url, .{ .source = .history, .value = json }, page, true);

// Update page URL and location so that location.pathname reflects the replaced state
page.url = url;
page.window._location = try Location.init(url, page);
}

fn goInner(delta: i32, page: *Page) !void {
Expand Down
Loading