Agent Zebra
Agent Zebra

Reputation: 4550

Make angular page refresh without Hash links?

How can I get angular to page refresh without Hash links? On page refresh my angular app would error and not show the page it was just displaying, so I changed the html5Mode to false ( $locationProvider.html5Mode(false).hashPrefix(""); ) and now I can refresh the page. But I'm also getting the nasty prefix #/ in the link path.

How do I remove # in the url path while at the same time be able to refresh the page?

Upvotes: 0

Views: 1244

Answers (3)

Parmod
Parmod

Reputation: 1243

Server rewrite will work on refresh, try to add middleware in your server. Sample grunt configuration id below. check https://github.com/parmod-arora/angular-url-rewrite for nginx and grunt serve rewrite.

middleware: function (connect) {<br>
        var middlewares = [];<br>
        middlewares.push(modRewrite([
          '!/assets|\\.html|\\.js|\\.css|\\woff|\\ttf|\\swf$ /index.html'
        ]));

        middlewares.push(connect.static('.tmp'));
        middlewares.push(connect().use(
          '/bower_components',
          connect.static('./bower_components')
        ));
        middlewares.push(connect.static(appConfig.app));

        //middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
        return middlewares;
      }

Upvotes: 1

user3681587
user3681587

Reputation: 566

Have you tried setting base in the head section of your html?

<!doctype html>
<html>
<head>
    <meta charset="utf-8">  
    <base href="/">
</head>

Upvotes: 1

allienx
allienx

Reputation: 887

Explore this thread: $location / switching between html5 and hashbang mode / link rewriting

You need to make sure all your links are absolute relative to index.html and you probably need a server rewrite.

Upvotes: 2

Related Questions