Removing the fragment identifier from AngularJS urls (# symbol)

后端 未结 14 2025
Happy的楠姐
Happy的楠姐 2020-11-22 00:01

Is it possible to remove the # symbol from angular.js URLs?

I still want to be able to use the browser\'s back button, etc, when I change the view and will update th

14条回答
  •  长发绾君心
    2020-11-22 00:39

    Follow 2 steps-
    1. First set the $locationProvider.html5Mode(true) in your app config file.
    For eg -
    angular.module('test', ['ui.router']) .config(function($stateProvider, $urlRouterProvider, $locationProvider) { $locationProvider.html5Mode(true); $urlRouterProvider.otherwise('/'); });

    2.Second set the inside your main page.
    For eg ->


    The $location service will automatically fallback to the hash-part method for browsers that do not support the HTML5 History API.

提交回复
热议问题