Skip to content

404.html file not being served #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fiznool
Copy link

@fiznool fiznool commented Apr 15, 2014

Currently the 404.html file in the app/views folder can't be served as express is sending index.html for any request that isn't an API call or a partial.

This PR uses the same methodology as for the partials - i.e. first express tries to render a file by the passed name, otherwise falling back to index.html. This way, custom error pages and any other static / server-side pages can be added to the app/views folder and served as normal.

@JaKXz
Copy link
Collaborator

JaKXz commented Apr 23, 2014

I know this is quite basic, but couldn't you just use the otherwise clause in app.js?

@fiznool
Copy link
Author

fiznool commented Apr 25, 2014

@JaKXz the use case I have is that express serves more than just the Angular app - perhaps a static information site, or other 'simple' pages that don't need Angular. In this case, routing to these other static pages is important - this covers the 404 page too.

@snowman-repos
Copy link

👍 I like to automatically generate a styleguide from the css using grunt-kss so this will be useful

@JaKXz
Copy link
Collaborator

JaKXz commented Jul 20, 2014

This issue is present in v2.x, any ideas for the correct solution?

@DaftMonk
Copy link
Member

Not sure exactly what the issue is here. All the html files located in the views folders are intended to be rendered with EJS, so to render one of the views you would add a route to your express routes:

app.route('/example').get(function(req, res) {
  res.render('example');
});

@JaKXz JaKXz removed the needs reply label Aug 5, 2014
@JaKXz
Copy link
Collaborator

JaKXz commented Aug 6, 2014

@DaftMonk I apologize for my delayed reply, but with v2.0.8, I can hit any URL and if the route is not registered in my app it will just go to /. I think There should be some feedback to the user that the route they're looking for doesn't exist.

@JaKXz JaKXz added the bug label Aug 10, 2014
@DaftMonk
Copy link
Member

Well for that problem we need to do handling of 404s on the client side. Instead of redirecting to / for unknown angular routes, we need to render a client side 404:

$urlRouterProvider
  .otherwise(function($injector) {
    $injector.get('$state').transitionTo('404');
  });

$stateProvider
  .state('404', {
    templateUrl: '/components/errors/404.html'
  });

@Awk34 Awk34 added this to the 2.3.0 milestone Jul 15, 2015
@Awk34 Awk34 modified the milestones: 3.0.0, 3.1.0 Aug 25, 2015
@Awk34 Awk34 modified the milestones: 3.1.0, 3.0.0 Nov 3, 2015
@Awk34 Awk34 closed this May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants