@@ -38,8 +38,14 @@ pub const Interfaces = .{
3838 NavigationHistoryEntry ,
3939};
4040
41- pub const NavigationKind = union (enum ) {
42- initial ,
41+ pub const NavigationType = enum {
42+ push ,
43+ replace ,
44+ traverse ,
45+ reload ,
46+ };
47+
48+ pub const NavigationKind = union (NavigationType ) {
4349 push : ? []const u8 ,
4450 replace ,
4551 traverse : usize ,
@@ -191,21 +197,26 @@ pub fn _forward(self: *Navigation, page: *Page) !NavigationReturn {
191197}
192198
193199// This is for after true navigation processing, where we need to ensure that our entries are up to date.
194- pub fn processNavigation (self : * Navigation , url : []const u8 , kind : NavigationKind , page : * Page ) ! void {
195- switch (kind ) {
196- .initial = > {
197- _ = try self .pushEntry (url , null , page );
198- },
199- .replace = > {
200- // When replacing, we just update the URL but the state is nullified.
201- const entry = self .currentEntry ();
202- entry .url = url ;
203- entry .state = null ;
204- },
205- .push = > | state | {
206- _ = try self .pushEntry (url , state , page );
207- },
208- .traverse , .reload = > {},
200+ // This is only really safe to run in the `pageDoneCallback` where we can guarantee that the URL and NavigationKind are correct.
201+ pub fn processNavigation (self : * Navigation , page : * Page ) ! void {
202+ const url = page .url .raw ;
203+ const kind = page .session .navigation_kind ;
204+
205+ if (kind ) | k | {
206+ switch (k ) {
207+ .replace = > {
208+ // When replacing, we just update the URL but the state is nullified.
209+ const entry = self .currentEntry ();
210+ entry .url = url ;
211+ entry .state = null ;
212+ },
213+ .push = > | state | {
214+ _ = try self .pushEntry (url , state , page );
215+ },
216+ .traverse , .reload = > {},
217+ }
218+ } else {
219+ _ = try self .pushEntry (url , null , page );
209220 }
210221}
211222
0 commit comments