1

In Angular2 cli I get a 404 when refreshing a route.

I'm using this seed app: https://github.com/2sic/app-tutorial-angular4-hello-dnn

When I do a: ng serve for a jit app it all works fine.

When I do a: https://github.com/2sic/app-tutorial-angular4-hello-dnn it works fine.

Until I do a refresh.

Tech I'm using: webpack, http-server (to run aot app), typescript, jit and aot builds with angular version 4

Example:

Navigate to pricing, pricing loads fine, then click refresh and you get a 404. I have a path called '**' which will redirect to home route if route not exist. But pricing route does exist and it doesnt redirect to home route either.

Some type of setting im missing with AOT routing here?

I'm using http-server ./dist to run my aot app

These are my routes (non are lazy loaded routes):

import { Routes } from '@angular/router';

import { HomeRoutes } from './components/home/home.routes';
import { ForgotPasswordRoutes } from './components/forgotPassword/forgotPassword.routes';
import { FaqRoutes } from './components/faq/faq.routes';
import { DbsRoutes } from './components/dbs/dbs.routes';
import { PricingRoutes } from './components/pricing/pricing.routes';
import { PrivacyRoutes } from './components/privacy/privacy.routes';
import { TermsRoutes } from './components/terms/terms.routes';
import { SiteMapRoutes } from './components/sitemap/sitemap.routes';
import { AboutRoutes } from './components/about/about.routes';
import { ContactRoutes } from './components/contact/contact.routes';

import { PageNotFoundRoutes } from './components/pageNotFound/pageNotFound.routes';

export const routes: Routes = [
    ...HomeRoutes,
    ...ForgotPasswordRoutes,
    ...FaqRoutes,
    ...SiteMapRoutes,
    ...PricingRoutes,
    ...PrivacyRoutes,
    ...TermsRoutes,
    ...AboutRoutes,
    ...ContactRoutes,
    ...DbsRoutes,
    ...PageNotFoundRoutes
];
AngularM
  • 15,982
  • 28
  • 94
  • 169
  • that's about routing a SPA, you need to redirect every request to `index.html`, it is not related to your application itself. – n00dl3 Apr 14 '17 at 14:31
  • I'm using http-server ./dist to run my aot app. How would I set the redirect to index.html? – AngularM Apr 14 '17 at 14:33
  • it seems it's not implemented on this server : [see this issue](https://github.com/indexzero/http-server/issues/80). – n00dl3 Apr 14 '17 at 14:40
  • I see, so no issue with my code, just with http-server not falling back to my index.html page? would be good to get a git bash command solution for this rather than creating a file with a fallback in? – AngularM Apr 14 '17 at 14:45
  • 1
    No issue with your code, indeed. I don't get what you mean by "good to get a git bash command solution for this rather than creating a file with a fallback in" buth there are litteraly hundreds of http server that can do such a thing, starting with apache and nginx, and about 50 http server implementations using nodejs. If you just google a bit for "http server spa" (single page app) or "http server pushstate" and you should find the server that matches your needs. – n00dl3 Apr 14 '17 at 14:53
  • Possible duplicate of [Angular 2 : 404 error occur when i refresh through Browser](http://stackoverflow.com/questions/35284988/angular-2-404-error-occur-when-i-refresh-through-browser) – jonrsharpe Apr 14 '17 at 15:22

0 Answers0