javascript - AngularJS 路由问题错误的 URL

标签 javascript angularjs node.js angularjs-ng-route

在我的应用程序中生成我的路线:

app.config( function($routeProvider){
    $routeProvider
        .when('/',{
            templateUrl: './partials/home/home.html',
            controller: 'mainCtrl'}
        )
        .when('/article',{
            templateUrl: './partials/article/article.html',
            controller: 'articleCtrl'}
        )
        .otherwise({
            redirectTo: '/'
    });

});

成功了!

但是链接是 bas :( 我这样创建我的链接:

<div class="read-more"><a href="#article">Lire plus...</a></div>

我的错误链接: http://localhost:10001/#!/#article

与好的链接是: http://localhost:10001/#!/article

谁错了?

谢谢

PS 我用的是 node lite-server

最佳答案

http://localhost:10001/#!/article是正确的网址。

原因是,如果浏览器是 HTML5 浏览器,AngularJS 会将其重定向到 #!

否则只会是#

阅读此 documentation here$location 上找到更多关于为什么会发生这种情况的信息。

  • Opening a regular URL in a legacy browser -> redirects to a hashbang URL
  • Opening hashbang URL in a modern browser -> rewrites to a regular URL

关于javascript - AngularJS 路由问题错误的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41859858/

相关文章:

javascript - 带有ajax xml请求的 Node js脚本不起作用

javascript - React 类函数中 this 为 null

javascript - ng-hide ng-show 无法正常工作

angularjs - SharePoint 列表上的 CRUD 与 Angular $resource

node.js - 一次将大量文件上传到 AWS S3

javascript - 网站是历史上的第一项吗?

javascript - 添加 form.submit 事件以确保在提交表单之前发布?

javascript - 如何将数据从 DB2 获取到 AngularJS 应用程序中?

javascript - ReactComponent 中的正则表达式标记按两个可能标记中的名称

windows - 如何在 Windows 上配置 npm-gyp 以使用 gcc 而不是 VC++?