手动重新加载页面时,Angularjs路由不起作用

时间:2015-11-30 01:38:18

标签: javascript jquery angularjs

我正在尝试从浏览器中手动重新加载页面,但它不起作用并且说

 Cannot GET /rate/4

我的路线:

    angular.module('routing')

.config(function ($routeProvider, $locationProvider) {

    $routeProvider

    .when('/', {
        templateUrl: 'app/views/index.html'
    })

    .when('/rate/:cid', {
        templateUrl: 'app/views/rate.html'
    })


    .otherwise({
        'redirectTo': '/'
    });

    $locationProvider.html5Mode(true);

});

我的假设是,当我重新加载main(index.html)时,没有加载哪个是我的基本html文件。

1 个答案:

答案 0 :(得分:0)

您没有角度问题,服务器出现问题。

您基本上使用的是单页应用程序。

当服务器收到rate/4的请求时,它必须返回index.html(或者您的主页所用的名称)。

如何解决这个问题取决于您在服务器上实施的平台。

例如,如果您正在运行节点快速服务器,那么您将拥有此类路由代码:

app.get(/^\/rate\/.*/, function(req, res) {
    // This matches a known pattern for a client-side route
    res.sendFile(__dirname + '\\public\index.html');
});