Skip to content
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

it does not work when i reload the browser after navigating to a route. #519

Open
NikitaPooja opened this issue Apr 25, 2019 · 7 comments

Comments

@NikitaPooja
Copy link

commented Apr 25, 2019

In angular 7, On running the dist on local machine , for the first time web page is loading. And when on reloading or hit the url, the page throwing the error.

I am used this link to run on the local machine

How to run the Dist Folder on Local Machine in Angular 6?

On Reload and for hit the url I am using .htaccess file. but Its not work.

I took the template build with command ng build --prod

I changed in index.html href="/browser/"

For run on the local machine I am used http-server.

First install the package globally using command

npm install http-server -g.

Then inside the project directory(in the terminal) just run

http-server dist/.
For the first time web page is loading on the local machine and when on reloading or hit the url, the page throwing the server error.

@thornjad

This comment has been minimized.

Copy link
Member

commented Apr 25, 2019

@NikitaPooja what is the error you're getting?

Also, .htaccess is a configuration file for the Apache server, http-server won't read it.

@rofrol

This comment has been minimized.

Copy link

commented Apr 29, 2019

I got the same. It does not support SPA.

@thornjad

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

@rofrol could you share the error you're seeing?

@thornjad thornjad added the needs-more label Apr 29, 2019

@rofrol

This comment has been minimized.

Copy link

commented Apr 29, 2019

No error, it just does not direct you to index.html for routes. This works for me with nginx:

events {
	worker_connections 768;
}

http {
	server {
		# Enable static gzip
		gzip_static on;

		listen 8080 default_server;
		listen [::]:8080 default_server;

		root /home/user/projects/project1;

		location / {
			try_files $uri /index.html;
		}
	}
}
@thornjad

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

@rofrol you are correct that http-server does not support fallback paths in the manner of try_files. However, you can use 404.html to sort-of support SPA. See #318 and #80.

@NikitaPooja is the error you're seeing when you say "the page throwing the server error" actually a 404 error, or is it an actual server error?

@rofrol

This comment has been minimized.

Copy link

commented Apr 29, 2019

@thornjad Great, it works with SPA:

http-server --gzip --proxy http://localhost:8080?

@thornjad

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

Oh yes that's a good hack too! We've got that coming into the README in #513!

This was referenced May 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.