Delete hashtag in url, make error when updating f5 (angularJs-cordova)

I have a question about the router in angularJs. I used angular -ui-router. but I get an error when deleting hashtag (#) in url with $ locationProvider. how to fix this problem ?, in my module:

.config(function($stateProvider, $urlRouterProvider, $locationProvider){
  $stateProvider

    .state('locale',{
      url: '/locale',
      templateUrl: 'template/static/locale.html'
    })

    .state('callback',{
      url: '/callback',
      templateUrl: 'template/static/callback.html',
      controller: 'userCalendar'
    })

    .state('sign_in',{
      url: '/sign_in',
      templateUrl: 'template/users/sign_in.html'
    })

    .state('addprofile', {
      url: '/addprofile',
      templateUrl: 'template/users/addprofile.html'
    })

    .state('tabs',{
      url: '/tabs',
      templateUrl: 'template/pages/tabs.html'
    })

    .state('tabs.mainMenu', {
      url: '/mainMenu',
      templateUrl: 'template/pages/mainmenu.html'
    })

    .state('form',{
      url: '#/form',
      templateUrl: '/template/users/form.html'
    })
  $urlRouterProvider.otherwise('locale');
  $locationProvider.html5Mode({
    enabled: true,
    requireBase: true
  });
});
Run code

Thank you for the attention

+4
source share
1 answer

Once you remove the hash routing, you will get this update problem (even without Cordoba). I see that you already have $ locationProvider with requireBase configuration app.js:

$locationProvider.html5Mode({enabled: true, requireBase: true});

This means that you also need to set the base URL to index.html:

<html ng-app="myApp">
<head>
<title>AngularJS</title>
<base href="http://localhost:8888/angularjs-website-folder/">

URL- . MAMP localhost .htaccess -:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /angularjs-website-folder/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(css|js|html|png|jpg|jpeg|gif|txt)
    RewriteRule (.*) index.html [L]
</IfModule>

NB: RewriteBase , url index.html .

0

All Articles