Bootstrap4 dropdown only works in the second click
you need to use the toggle like that and assign the data-target
to the drop down menu with it's id
using
data-target="#navbarDropdown"
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
and then assign that id to the menu
<li class="nav-item dropdown show">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarDropdown" class="dropdown-menu" role="menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item">Link 1</a>
<a class="dropdown-item">Link 2</a>
</div>
</li>
I came across the same issue recently, i solved this issue by adding $('.dropdown-toggle').dropdown() after loading the drop-down. Hope this may help without changing from the data-toggle="dropdown" to data-toggle="collapse".
I had the same problem then resolved. Often I due to a double import of bootstrap js libraries. Hope will help you.