rappasoft / laravel-boilerplate

The Laravel Boilerplate Project - https://laravel-boilerplate.com
https://rappasoft.com
5.59k stars 1.58k forks source link

Conflict in backend.js causing nav anchor tag to not append to URL #1593

Closed digitalredefned closed 2 years ago

digitalredefned commented 2 years ago

I created a tab section of a page for a view using the backend app blade and noticed that when clicking the tabs, the anchors were not being appended to the URL of the account page on the front end.

To debug

The code that performs this looks the same in both files so I'm assuming something else in the file may be causing a conflict.

poseso commented 2 years ago

Try this:

// Change Tab on load let hash = window.location.hash; hash && $('ul.nav a[href="' + hash + '"]').tab('show');

$('.nav-tabs li > a').on('click', function (e) {
    $(this).tab('show');
    history.pushState(null,null, this.hash);
});

$(window).bind('hashchange', function(){
    $('ul.nav a[href^="' + document.location.hash + '"]').click();
});

if (document.location.hash.length) {
    $(window).trigger('hashchange');
}
digitalredefned commented 2 years ago

This worked with the modification below since these links aren't nested in a list: $('.nav-tabs > a.nav-link').on('click', function (e) { $(this).tab('show'); history.pushState(null,null, this.hash); });

Appreciate the response and hope you're safe in the DR!

poseso commented 2 years ago

Glad it helped you and worked with the modification, and thanks for your concern of me in the DR :D