0

My HTML5 mode site has a 404 state which I would like to enable except for anything that comes from /pages/, as those are being served from a server-side CMS -Mezzanine-. Any ideas?

$stateProvider
    .state('app.404', {
      url: '*path',
      views: { 'main': { templateUrl: '/static/app/views/404.html' } }
    })
rebelliard
  • 9,592
  • 6
  • 47
  • 80

1 Answers1

0

If I'm understanding correctly, then I think this needs to be handled on the server side. I have done something similar, where I had only a few urls that I wanted to render on the server, and all other urls were directed to what basically amounted to index.html, which is where my angular app was located.

This can be tricky, because your static resources obviously need to be served outside of these parameters.

Without knowing what your stack is on the server I can only suggest the technique that I used, which was to have my angular app at '/', but to have all routes in the angular app to be use the same prefix (in my case '/manage/*'.

Then, on the server side, /manage/* was redirected to index.html and everything else was served as usual.

A similar and more error prone solution might try to redirect everything except the resources that you want served normally. For Apache, the .htaccess might look something like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^js|css|img|templates|static|pages
RewriteRule .* index.html

I say it's error prone only because you need to make sure and keep it updated if there are any other resources that you will be serving from your domain, or at least make sure you remember what you have done when debugging.

trey-jones
  • 3,329
  • 1
  • 27
  • 35
  • Having to have "manage" it all your urls seems a bit annoying, I normally do the opposite, so put up an ignore pattern for /assets/* and puts all assets that needs to be provided as is from the server under that, if I have a set of rest services i put them up under /api/*... , finally after all other routes I route * to index.html... as it evaluates this last this works perfectly. And I believe most routing systems works like that. – Jens Oct 12 '14 at 18:39