I use endurolytes from Hammer Nutrition. It's supplement you can take to help replenish your electrolytes during a ride.

There's lots of other products out there. You may need to experiment some to find what works for you.