question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

404 when reloading route o ng build --prod

See original GitHub issue

Info

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

-Mac OSX El Capitan

  1. Versions. Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.11-webpack node: 6.3.0 os: darwin x64

  1. Repro steps. Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

I’m geting a weird error, when I reload on any route with the cli (example “app/route”), everything works fine, but if I i “ng build --prod”, and then test it, if I reload on that particular route (‘app/route’), it gives me a 404 error instead of actually working, Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
Abubarrettcommented, Oct 24, 2016

Yeah the basic idea is that the server loads routes based on files, but your whole angular app runs on index.html and it tells the browser which route to show, so with htaccess you pretty much route all server incoming traffic to index.html and it all runs smoothly 😃 This is the .htaccess I’m using:

RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
1reaction
Abubarrettcommented, Sep 12, 2016

Thank you @filipesilva, sorry for the confusion haha

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2: 404 error occur when I refresh through the browser
To fix the 404 error, you need to update your server to serve the index.html file for each route path you defined. If...
Read more >
Angular 6+ deploy to server/ solve 404 Not Found error on ...
This article will hep you to deploy angular 6+ application on apache server also to solve 404 not found error on page refresh....
Read more >
The requested URL was not found on this server error in Angular
Angualr throws the requested URL was not found on this server (404 not found). It appears that angular routing not working on the...
Read more >
How to setup 404 page in angular routing ? - GeeksforGeeks
To set up a 404 page in the angular routing, we have to first create a component to display whenever a 404 error...
Read more >
Deployment - Angular
When you are ready to deploy, however, you must use the ng build command to build ... This is the simplest production-ready deployment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found