You don't stop riots by shooting at them. You stop riots by preventing or resolving the economic and social conditions that lead to them; that is, by improving the quality of life of those who have the lowest quality of life.
Unfortunately, shooting at them is easier to both conceptualize and implement, so governments tend to simply do that anyway.
That is... really complicated. 'Just improve their standard of living bro' isn't a real solution. It's like saying we can prevent murder by systemically renouncing violence and becoming a more peaceful society. This is obviously true, but the path forward is not obvious.
Unfortunately, shooting at them is easier to both conceptualize and implement, so governments tend to simply do that anyway.