Ad

Why Laravel Bootstrap Drowdown Not Working

- 1 answer

here is my navbar

<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
    <a class="navbar-brand" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/">TeaShirt</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/design">Desing your Teashirt</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/about">About Us</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/contact">Contact</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/checkout">Checkout</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="/teashirt/public/cart" tabindex="-1" aria-disabled="true">Cart</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" target="_blank" rel="nofollow noreferrer" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Guest!</a>
                <div class="dropdown-menu" aria-labelledby="dropdown01">
                    <a class="dropdown-item" target="_blank" rel="nofollow noreferrer" href="#">Profile</a>
                    <a class="dropdown-item" target="_blank" rel="nofollow noreferrer" href="#">Another action</a>
                    <a class="dropdown-item" target="_blank" rel="nofollow noreferrer" href="#">Logout</a>
                </div>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
            <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
        </form>
    </div>
</nav>

Here is my bootsrap.js

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

here is my app.js

require('./bootstrap');

Visual Studio Code offered to replace require to import, did that it didnt work.

I have tried -popper upgrade -composer update

Nothing is working. Everything works on the navbar but when i click dropdown it just goes to the link /#. I have tried it on IE and chrome. Same result

Ad

Answer

Adding this just before the `</body>` tagsolved my problem. 

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

I have tried it brfore too. But i think I have tried so many things that i cant tell why it didnt work before now it did.

Ad
source: stackoverflow.com
Ad