P
P
Peter2015-11-02 00:50:58
Angular
Peter, 2015-11-02 00:50:58

How to setup angular-route with html5?

I need to set up routing in Angular using html5, i.e. without # .
I did the settings for the angular-route module correctly, but when I click on the direct link, the required page does not open.
Apparently not the correct settings on the server side.
In the project (in the app folder) for Apache there is a .htaccess file, but the settings prescribed in it somehow do not work correctly (I took them from the Internet).
What is the error and how to write it correctly?
Also interested in server settings for IIS, node.js and nginx (especially for node.js).
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2015-11-02
@healqq

Your rewrites are terrible. In general, the point is - we check if a physical file exists at the URL, if not, we redirect to index.html.
Apache looks like this:

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]

In general, for ui-router there is a very good dock with settings for different occasions. There are no differences from the standard router in this case.

S
sasha, 2015-11-02
@madmages

two options. (provided that the angular itself is normally configured)
1. do all redirect links (http code 302) on the server to one root page and the angular itself will already be on it.
2. Send the same page to the request of any page (this method is preferable).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question