Removing the fragment identifier from AngularJS urls (# symbol)

后端 未结 14 2005
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:50

    Start from index.html remove all # from About Us so it must look like About Us.Now in head tag of index.html write just after last meta tag.

    Now in your routing js inject $locationProvider and write $locatonProvider.html5Mode(true); Something Like This:-

    app.config(function ($routeProvider, $locationProvider) {
        $routeProvider
            .when("/home", {
                templateUrl: "Templates/home.html",
                controller: "homeController"
            })
                .when("/aboutus",{templateUrl:"Templates/aboutus.html"})
                .when("/courses", {
                    templateUrl: "Templates/courses.html",
                    controller: "coursesController"
                })
                .when("/students", {
                    templateUrl: "Templates/students.html",
                    controller: "studentsController"
                })
            $locationProvider.html5Mode(true);
        });
    

    For more Details watch this video https://www.youtube.com/watch?v=XsRugDQaGOo

提交回复
热议问题