Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS routing hijacking non base URLs when page reload is expected
    text
    copied!<p>I'm building an AngularJS app that is not located in the root location <code>domain.tld/blog</code>. I have routing setup for everything on the <code>/blog</code> base. I included the base tag in the head of the page <code>&lt;base href="/blog"&gt;</code>. <code>html5Mode</code> is set to <code>true</code>. Within the app everything works as expected. However, when I click a non-angular URL outside of the base location the page isn't loaded. It seems that this location is caught by the <code>otherwise</code> function in the router:</p> <pre><code>ROUTER.otherwise({ redirectTo : '/blog' }); </code></pre> <p>So when I click any url, i.e. <code>domain.tld/somewhere-else</code> it redirects to domain.tld/blog. Obviously this is what you would expect: for every URL that is not found in the router, redirect it to the 'homepage'. In my app this is not the desired behavior. All urls that are not in the router should be treated as a normal url and fire a page reload to that url. </p> <p>So what I need is something like this:</p> <pre><code>ROUTER.otherwise( window.location = theRequestedUrl; ); </code></pre> <p>This doesn't work obviously. But somehow I need to get inside the otherwise part of the router and tell it to redirect to page with a page reload.</p> <p>The following question is related: <a href="https://stackoverflow.com/questions/15704720/angular-routing-something-weird-happening">angular routing something weird happening</a></p> <p>The following jsFiddle demonstrates the problem (thanks @rdjs!) <a href="http://fiddle.jshell.net/43tub/6/show/light/" rel="nofollow noreferrer">http://fiddle.jshell.net/43tub/6/show/light/</a> . Click on the <code>/outside</code> link should do a full page refresh...</p>
 

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