title: How to properly navigate backstack in Windows Phone 8.1 universal store app
body: <p>Here's the scenario for my page navigation:</p>
  
  <p>MainPage (MP) &lt;==> Locations (L) &lt;==> AddLocation (AL)</p>
  
  <p>I don't want the user to ever go to AddLocation when hitting the back button on the phone.</p>
  
  <p>If they are on MP and they hit back, they should exit the app.</p>
  
  <p>If they went MP->L and hit back, they should go to MainPage.</p>
  
  <p>If they went MP->L->AL and hit back, they should go to Locations.</p>
  
  <p>If they went MP->L->AL->L and hit back, they should go to MainPage and not back to AddLocations.</p>
  
  <p>Right not, I have the standard nav helpers in the Common folder and then I've added this code to the Locations page to make this happen:</p>
  
  <pre><code>protected override void OnNavigatedTo(NavigationEventArgs e)
  {
      this.navigationHelper.OnNavigatedTo(e);
      var bs = Frame.BackStack.Where(b =&gt; b.SourcePageType.Name == "MainPage").FirstOrDefault();
      if (bs!= null)
      {
          Frame.BackStack.Clear();
          Frame.BackStack.Add(bs);
      }
  }
  </code></pre>
  
  <p>This seems to be a terrible hack to me and I'm sure there some supported/designed way to do this that I don't know about.  I'm very new to WinRT and Xaml.</p>