I am using angular for my app
I wanted to remove the # from the url so i added the below lines as suggested in SO answer
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
In the index.html I also added the below code as suggested here
<head>
<base href="/">
</head>
It all works fine when I navigate to pages from the home, but when i copy the url and open it in new tab, it throws 404 error
Example
When I launch the app, it's opening http://localhost:portno/home
.
When I refresh the page, I'm getting a 404 error.
What other configuration should i make?
You need to add a route
on your server that will redirect you to the entrypoint of your front (i.e: index.html
).
For example, if you were redirected from your home to http://localhost:portno/foo/bar
, you'll need a route
to match the /foo/bar
one that will redirect you to your index.html
.
It migth look like this (note that this is an example code of my own written for Hapi):
server.route([
{
method: 'GET',
path: '/foo/bar',
handler: function(request, reply) {
reply.file('./public/index.html');
}
}
...