Bayonet charges were a major aspect of Napoleonic warfare, and only really went away with the development of firearms that had higher rates of fire and were accurate out to larger ranges. In the Napoleonic era, soldiers would close to within 50-100 meters, fire off a few volleys, and then charge in with the bayonet.
By the time armies were equipped with breech-loading rifles that could fire half a dozen accurate shots a minute at a distance of a few hundred meters, the volume and accuracy of fire made the bayonet charge obsolete. But that was rather late (the 1860s or so).