Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The documentation is not very clear about AngularJS routing. It talks about Hashbang and HTML5 mode. In fact, AngularJS routing operates in three modes:</p> <ul> <li>Hashbang Mode</li> <li>HTML5 Mode</li> <li>Hashbang in HTML5 Mode</li> </ul> <p>For each mode there is a a respective LocationUrl class (LocationHashbangUrl, LocationUrl and LocationHashbangInHTML5Url).</p> <p>In order to simulate URL rewriting you must actually set html5mode to true and decorate the $sniffer class as follows:</p> <pre><code>$provide.decorator('$sniffer', function($delegate) { $delegate.history = false; return $delegate; }); </code></pre> <p>I will now explain this in more detail:</p> <h1>Hashbang Mode</h1> <p>Configuration:</p> <pre><code>$routeProvider .when('/path', { templateUrl: 'path.html', }); $locationProvider .html5Mode(false) .hashPrefix('!'); </code></pre> <p>This is the case when you need to use URLs with hashes in your HTML files such as in</p> <pre><code>&lt;a href="index.html#!/path"&gt;link&lt;/a&gt; </code></pre> <p>In the Browser you must use the following Link: <code>http://www.example.com/base/index.html#!/base/path</code></p> <p>As you can see in pure Hashbang mode all links in the HTML files must begin with the base such as "index.html#!".</p> <h1>HTML5 Mode</h1> <p>Configuration:</p> <pre><code>$routeProvider .when('/path', { templateUrl: 'path.html', }); $locationProvider .html5Mode(true); </code></pre> <p>You should set the base in HTML-file</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;base href="/"&gt; &lt;/head&gt; &lt;/html&gt; </code></pre> <p>In this mode you can use links without the # in HTML files</p> <pre><code>&lt;a href="/path"&gt;link&lt;/a&gt; </code></pre> <p>Link in Browser:</p> <pre><code>http://www.example.com/base/path </code></pre> <h1>Hashbang in HTML5 Mode</h1> <p>This mode is activated when we actually use HTML5 mode but in an incompatible browser. We can simulate this mode in a compatible browser by decorating the $sniffer service and setting history to false.</p> <p>Configuration:</p> <pre><code>$provide.decorator('$sniffer', function($delegate) { $delegate.history = false; return $delegate; }); $routeProvider .when('/path', { templateUrl: 'path.html', }); $locationProvider .html5Mode(true) .hashPrefix('!'); </code></pre> <p>Set the base in HTML-file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;base href="/"&gt; &lt;/head&gt; &lt;/html&gt; </code></pre> <p>In this case the links can also be written without the hash in the HTML file</p> <pre><code>&lt;a href="/path"&gt;link&lt;/a&gt; </code></pre> <p>Link in Browser:</p> <pre><code>http://www.example.com/index.html#!/base/path </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload