skip to Main Content

I want to remove # from my angularjs app, I am developing an website, I think it may help to make SEO friendly website, May be i am wrong, Please help
Thanks

2

Answers


  1. Config

    To remove the # in your url you need to add this to your main module. You put the app into html5 mode.

    //This config is used to remove the # in the html
    app.config(["$locationProvider", function($locationProvider) {
       $locationProvider.html5Mode({
            enabled: true,
            requireBase: false
       });
    }]);
    

    Server Side (NodeJS)

    This will have a server side effect when you hit refresh you need to add an extra route that is able to find the new url. this will work in your express js app.js file. Where the public folder contains your angular app and you have your index.html file in there

    // ### CATCH REFRESH TO INDEX ###
    app.all('/*', function(req, res, next) {
        // Just send the index.html for other files to support HTML5Mode
        res.sendFile('public/index.html', { root: __dirname });
    });
    
    Login or Signup to reply.
  2. I agree with Joe Lloyd for the way to remove the # from your url but it won’t help you to make your angularjs website crawlable.
    Check out the following steps :

    1. Configure the html5mode

      config(function ($routeProvider, $locationProvider) {
      $locationProvider.html5Mode(true);

    2. Add <meta name="fragment" content="!"> to your pages so the google bot knows to add the ?_escaped_fragment_= at the end of your request.

    3. Handle the ?_escaped_fragment_=on the server side and serve a static snapshot of the requested html page (phantomjs can make the job) so the bot will index the rendered version of the html page.

    4. Populate your sitemap.xml and send it to google using http://www.google.com/webmasters/

    Have fun !

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search