简体   繁体   English

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

[英]Angularjs routing doesnt work when reloading the page manually

I am trying to reload the page mannually from the browser but it doesn't work and says 我正在尝试从浏览器手动重新加载页面,但是它不起作用并说

 Cannot GET /rate/4

My route: 我的路线:

    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);

});

My assumption is that when I am reloading the main (index.html) is not loaded which is my base html file. 我的假设是,当我重新加载主文件(index.html)时,它是我的基本html文件。

You do not have an angular problem, you have a server problem. 您没有角度问题,有服务器问题。

You're essentially working with a single page application. 本质上,您正在使用单页应用程序。

When the server receives a request for rate/4 it must return index.html (or whatever the name that your main page is). 当服务器接收到关于rate/4的请求时,它必须返回index.html (或主页的名称)。

How you solve this will depend upon what platform you've implemented your server in. 如何解决此问题将取决于您在其中实现服务器的平台。

For example, if you were running a node express server, you would have this kind of routing code: 例如,如果您正在运行节点快速服务器,则将具有以下路由代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM