Basically, instead of waiting for an employee to leave to do an exit review to understand WHY, do periodic interviews (i.e. one-on-ones) about how to keep someone happy and engaged.
What do you look forward to when you come to work each day?
What do you like most or least about working here?
What keeps you working here?
If you could change something about your job, what would that be?
What would make your job more satisfying?
How do you like to be recognized?
What would you like to learn here? What motivates (or demotivates) you?
What can I do to best support you?
What can I do to add value to you?
What can I do more of or less of as your manager?
What might tempt you to leave?