带有/?#/的奇怪路由行为angularJS [英] Strange route behaviour angularJS with /?#/

查看:54
本文介绍了带有/?#/的奇怪路由行为angularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上在AngularJS中遇到路由问题.实际上,当我第一次启动一个页面时,当前网址是" http://www.test.com/#/roadmaps/edit ".

I m actually facing a problem with routes in AngularJS. In fact, when I launch one of my page for the first time, the current url is "http://www.test.com/#/roadmaps/edit".

当我单击页面上的任何按钮时,页面都会刷新并为我提供一个新的URL,例如:""在#"之前.

When I click on any button of the page, my page refreshes and gives me a new URL like : "http://www.test.com/?#/roadmaps/edit" with the "?" before the "#".

因此,每次我在页面中填写不同的输入并单击一个按钮时,第一次刷新(有问题...)并显示?"符号出现在URL中.

So everytime I fill the different input in my page and click a button, the first time it refreshes (problematic...) and make the "?" symbol appears in the URL.

你有个主意吗?

这是我实际的路由功能:

This is my actual routing function:

function config($routeProvider) {
    $routeProvider.
        when('/roadmaps/edit', {
            templateUrl: 'partials/roadmap_edit.html',
            controller: 'RoadMapEditCtrl'
        }).
        when('/roadmaps/edit/:id', {
            templateUrl: 'partials/roadmap_edit.html',
            controller: 'RoadMapEditCtrl'
        })
}

第一行用于添加路线图,第二行用于修改.

The first line is for adding a roadmap and the second one to modify.

你能帮我吗?

感谢前进

这是导致此问题的按钮之一:

This is one of the buttons that causes this problem :

<li>
 <button style="margin-top:10px;" ng-click="selectAll()">Tout {{selectionner}}
</button>
</li>

还有selectAll()函数:

And the selectAll() function :

var isSelectedJour = false;
    $scope.selectAll = function () {
        if (isSelectedJour) {
            $scope.selectionner = "cocher";
        } else {
            $scope.selectionner = "décocher";
        }

        isSelectedJour = !isSelectedJour;

        $scope.mo = isSelectedJour;
        $scope.tu = isSelectedJour;
        $scope.we = isSelectedJour;
        $scope.th = isSelectedJour;
        $scope.fr = isSelectedJour;
        $scope.sa = isSelectedJour;
        $scope.su = isSelectedJour;
    };

推荐答案

在这里参加聚会很晚,但这是原因和两个解决方案:

Very late to the party here, but here is the cause and two solutions: ReactJS with React Router - strange routing behaviour on Chrome. The cause is ANY button click getting treated as a submit and the form not having a submit action target. One solution is to add a preventDefault event handler. As I noted in a comment, all I needed to do to fix it was change <button> to <span>.

这篇关于带有/?#/的奇怪路由行为angularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆