P
P
pLavrenov2015-11-08 16:45:41
Angular
pLavrenov, 2015-11-08 16:45:41

Direct links not working without # in angular.js"?

app.config(function($routeProvider, $locationProvider) {
  $routeProvider
  .when('/', {
    templateUrl:'/tpl/1.html'
  })
  .when('/page2', {
    templateUrl:'/tpl/2.html'
  })
  .otherwise({
    redirectTo:'/'
  });
  
  $locationProvider.html5Mode(true);
});

There is a simple router, hashtags are disabled, when you normally follow a link from a page, everything works, and if you type localhost/page2 in the address bar, then Not Found. Please tell me how to solve
. Solved. need to add to .htaccess
<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [L]
</IfModule>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question