2

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".

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 "#".

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.

Do you have an idea ?

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.

Can you help me ?

Thanks for advance

EDIT :

This is one of the buttons that causes this problem :

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

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;
    };
mfrachet
  • 8,772
  • 17
  • 55
  • 110

2 Answers2

1

Hi you can contour it using

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

        $locationProvider.html5Mode(true);
}
vmontanheiro
  • 1,009
  • 9
  • 12
  • The # isnt a problem :/ it's the "?" symbol that is problematic – mfrachet Nov 07 '14 at 13:28
  • Think it happens because you are sending some parameter in your URL. If I found the answer I will post here for you again. Hugs! – vmontanheiro Nov 07 '14 at 13:37
  • Tested without the route parametered and there is the same problem – mfrachet Nov 07 '14 at 13:40
  • mmm, I tested in my project here and the url didnt show any "?". How about your code html, are you using href, ng-href or ui-sref ? Or are you just calling the url in your browser ? – vmontanheiro Nov 07 '14 at 13:47
  • I dont use anyone of these, it appears on button elements that has only ng-click functions associated, without any redirection inside the functions. – mfrachet Nov 07 '14 at 13:50
1

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>.

Community
  • 1
  • 1
ckapilla
  • 1,148
  • 13
  • 25