AngularJS routing: ignore request parameters when routing

It should be simple, but I do not find the right solution anywhere.

// Routing file
    ...
    .when('/pathA', templateA)
    .when('/pathB', templateB)
    .otherwise({ redirectTo: '/lollz' });

Both paths have many optional query parameters. Pages work when there are no parameters, but every time I pass a parameter, the router goes to the page /lollz. How can I make the router ignore request parameters and focus only on sub-paths?

+4
source share
1 answer

The problem was somewhere else, I made the error of passing request parameters in $location.pathlike:

$location.path('/pathA?param1=aaa'); // which kept getting encoded into /pathA%3Fparams1=aaa

As soon as I started passing request parameters in the chain search, the problem disappeared:

$location.path('/pathA').search({params1:'aaa'});
+1
source

Source: https://habr.com/ru/post/1624209/


All Articles