Look at existing plugins that already do it. It's not an easy/short explanation. The alternative is to use the "New Menu" system (not necessarily better, just different) which does all the pages automatically for you.
mapsmenu.sma is on example that does it with the traditional menu system.