Skip to content

Commit

Permalink
set data in pushState to load page with tab param
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBudz committed Jun 24, 2024
1 parent 28fee46 commit 489b982
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions app/assets/javascripts/shared/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,11 @@
let currentTab = $(e.target).attr('href').substring(1);
searchParams.set('tab', currentTab);
let urlWithTab = `?${searchParams.toString()}`;
history.pushState(null, null, urlWithTab);
});

// Allows users to navigate using the native browser back/forward buttons
// even when we manipulate the browser history with pushState()
$(window)
.off()
.on('popstate', function () {
if (location.search.length) {
Turbolinks.visit(location, { action: 'replace' });
}
history.pushState(
{ turbolinks: true, url: urlWithTab },
'',
urlWithTab
);
});
}

Expand Down

0 comments on commit 489b982

Please sign in to comment.