Check out this page under “Layout / MasterPage Scripting - The Basics”
In short, you create a master template and insert placeholders for where your content will appear ...
How exactly this works depends on the viewing mechanism used (Razor, etc.)
EDIT:
WRT History/Back, history.js . . , ( AJAX - ).