Still getting 'Not Found' when manually refreshing with angular.js route

后端 未结 4 812
孤街浪徒
孤街浪徒 2021-01-17 19:30

After reading a ton of write-ups and stackoverflow questions on Angular.js route, I\'m still getting the \'Not Found\' error when I do a manual refresh.

Steps:

4条回答
  •  太阳男子
    2021-01-17 20:12

    I don't know if this is the optimal solution, but I did find a combination of settings that worked:

    • Include the hashPrefix('!') (see below)
    • Did not include in my index.html
    • Added FallbackResource /index.html to my section in my server .conf file per this post. After setting this, it didn't seem to matter what the local mod_rewrite settings were.
    // Routing configuration.
    angular.module('myModule')
        .config(['$routeProvider', '$locationProvider', 
        function ($routeProvider, $locationProvider) {
            // Enable pushState in routes.
            $locationProvider.html5Mode(true).hashPrefix('!');
    
            $routeProvider
                .when('/home', {
                    templates: {
                        layout: '/views/home.html'
                    },
                    title: 'Welcome!'
    
                })
                .when('/launchpad', {
                    templates: {
                        layout: '/views/layouts/default.html',
                        content: '/views/partials/profile.html'
                    },
                    title: "Launchpad"
                })
                .otherwise({
                    redirectTo: '/home'
                });
    
        }
    ]);
    

提交回复
热议问题