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

后端 未结 4 806
孤街浪徒
孤街浪徒 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:08

    This .htaccess setting worked well for me

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^/$
        RewriteRule (.*) /#!/$1 [NE,L,R=301]
    </IfModule>
    
    0 讨论(0)
  • 2021-01-17 20:11

    I couldn't comment but as well as using HTML mode, base href="/", sudo a2enmod rewrite, using .htaccess rewrite. From Unispaw, I had to AllowOverride All in both the sites available of your site and the /etc/apache2 apache.conf

    0 讨论(0)
  • 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 <base href="/"> in my index.html
    • Added FallbackResource /index.html to my <Directory PATH_TO_WWW_FILES> 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'
                });
    
        }
    ]);
    
    0 讨论(0)
  • 2021-01-17 20:14

    For people who are still facing this error, with or without SSL:

    Make sure you Allowoverride in your apacheconfig e.g.

    <Directory "/var/www/mysite/public_html">
        AllowOverride All
    </Directory>
    

    for both ports is u use SSL

    0 讨论(0)
提交回复
热议问题