0

Is there a way to prevent Angular from changing the hash part of the URL?

I still want to be able to navigate from one controller+view to another, though. However, I specifically do not want the user to be able to go to a specific page in Angular. The user should only be able to open the first, main, controller+view. I also would like to make sure the history is not modified either.

Maxwell175
  • 1,954
  • 1
  • 17
  • 27
  • In *theory*, you could use a state provider like UI-Router and only use calls to change state, rather than the default `ngRoute`... http://slides.com/timkindberg/ui-router#/10. In practice, this is much more difficult than it might seem on the surface. – Claies May 09 '16 at 00:53
  • @Claies: So using a compile directive like so http://stackoverflow.com/a/17426614/1610754, I can make it contain a div with `data-ng-controller` and just inject the view into it, and this will be easier than doing pretty much anything else, right? – Maxwell175 May 09 '16 at 02:00
  • I've not seen anything like that ever used, and I'm not sure how that relates to my comment about using a state provider... That being said, that certainly looks like another possible solution; feel free to post a self answer if you happen to make something work. – Claies May 09 '16 at 04:01

1 Answers1

1

If you only want the user to have certain parts of your app navigated via AngularJS and the rest to be handled by your whatever normal routing your server used then I recommend silo-ing your Angular App. By that, I mean you could have your app loaded in it's own scope, instead of at the base of your HTML <html> or <body>

<html>
<head> ... </head>
<body>
  <div id="site">
    <header> ... </header>
    <div id="content">
      ...
      <div data-ng-app="AngularApp" data-ng-controller="HomeController">
        <div data-ng-include="template-to-render"></div>
      </div>
    </div>
    <footer> ... </footer>
  </div>
</body>
Pixxl
  • 945
  • 10
  • 18
  • Your answer inspired me with a solution. See my comment on the main post. – Maxwell175 May 09 '16 at 01:29
  • That's what collaborative solutions are there for haha! Yeah, I realized after getting into Angular you don't have to just have one app on a page, but instead have separate apps or directives to handle simple tasks. – Pixxl May 09 '16 at 02:49