You can do this:
$("a.nav-link").click(function(e,i){
if(i){
var hash = i.ancora ? i.hash : i;
}else{
var hash = this.href.match(/#.+/)[0];
}
$(hash + '.collapse').collapse('show');
if(i) hash = i.ancora || hash;
$('html, body').animate({ scrollTop: $(hash).offset().top - 200 }, 500);
});
$(document).ready(function(){
var hash = location.hash;
var params = hash;
if(!$(hash).hasClass('collapse')){
hash = "#"+$(hash).closest(".collapse").attr("id");
params = {hash: "#"+$(hash).closest(".collapse").attr("id"), ancora: params};
}
if(hash) $("a.nav-link[href$='"+hash+"']").trigger("click", params);
});
If there is a hash in the URL or if you click on the menu, it will trigger the click
event where you will open the collapse.