You will want to extend the Walker_Nav_Menu class. This allows you to “walk” through the various states of a navigation menu. One of the first google searches I did for the term Walker_Nav_Menu
led me to this Github repo with a class already built. wp-bootstrap-navwalker.