Do not annotate ui-router's $urlRouterProvider.otherwise
See original GitHub issueCurrently, this:
$urlRouterProvider.otherwise(function ($injector) {
//...
});
is being annotated into:
$urlRouterProvider.otherwise(["$injector", function ($injector) {
//...
}]);
But ui-router
expects a function:
this.otherwise =
function (rule) {
if (isString(rule)) {
var redirect = rule;
rule = function () { return redirect; };
}
else if (!isFunction(rule)) throw new Error("'rule' must be a function");
otherwise = rule;
return this;
};
and already passes $injector
as a parameter to otherwise
:
function update() {
function check(rule) {
var handled = rule($injector, $location);
if (handled) {
if (isString(handled)) $location.replace().url(handled);
return true;
}
return false;
}
var n=rules.length, i;
for (i=0; i<n; i++) {
if (check(rules[i])) return;
}
// always check otherwise last to allow dynamic updates to the set of rules
if (otherwise) check(otherwise);
}
I’m not being able to keep ng-annotate
from annotating this by using:
regexp: /^((?!otherwise).)*$/
I probably misunderstood the regexp
option, though.
Workaround:
var urlRouterProvider = $urlRouterProvider;
urlRouterProvider.otherwise(function ($injector) {
//...
});
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
ui-router dosn't work with $urlRouterProvider.otherwise
I tried this before my post in stackoverflow, but don't work. – dani. Jan 31, 2018 at 8:12. Add a comment ...
Read more >Routing in Angular JS using Angular UI Router - GeeksforGeeks
Angular-UI-Router has stateProvider method which is used to create routes/states in application. State Provider takes state name and state ...
Read more >ui-router/CHANGELOG.md at master · angular-ui/ui ... - GitHub
The de-facto solution to flexible routing with nested views in AngularJS - ui-router/CHANGELOG.md at master · angular-ui/ui-router.
Read more >From ui-router to Component Router - Telerik Blogs
otherwise to set up a fallback if a valid route is not found. function config($stateProvider, $urlRouterProvider) { $stateProvider ...
Read more >Url.urlrouterprovider - UI-Router
Returns void · otherwise(rule: string | RawNg1RuleFunction): UrlRouterProvider · Defines the path or behavior to use when no url can be matched.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I took a look at
ui-router
’s source and then ran a few tests.Takeaways:
when
can handle an array with annotations and a function, i.e. this is OK:Proof:
rule
norotherwise
will accept an array and will throw if that’s the case:$urlRouterProvider
’s only public (and documented) functions arewhen
,rule
, andotherwise
; so perhaps includinganythingreally
might bite us if new functions which can’t be annotated are added toui-router
in the future (but it is entirely up to you to make this call 😃).Never mind… I had two “config” functions (one for my module config and another from a directive’s config, which came from a template I purchased), and I was blaming the module config the whole time. I finally came to realization when I enabled
ng-strict-di
. That clearly told me the name of the piece causing the issue, and then I was able to narrow it down.