So I am using UI-Router to build my AngularJS app. However I am confused as to how the URL Routing works in case of nested states mainly due to the conflicting ideas (as per my understanding) provided in the wiki for UI-Router.
The first idea
Hence maybe abstract state is used below
The second idea
As given in the documentation (first idea), url of parent state is prepended to that of it's children only in case of 'abstract':true property defined on the parent state.
However the documentation (second idea) also mentions how the above is a default feature.
Aren't the two ideas above conflicting for the same concept ? Or have I completely misunderstood them ?
The ui-view directive tells angularJS where to inject the templates your states refer to. When a state is activated, its templates are automatically inserted into the ui-view of its parent state's template. If it's a top-level state—which 'business' is because it has no parent state–then its parent template is index.
$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.
State-Based Routing is a type of Geographic Routing that automatically directs your callers to the most appropriate store or office in their state or territory when they call your 1300/1800/13 or Local Virtual number.
UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).
Well, the documentation statements are correct. Maybe not clear for someone - but correct. It simply says:
1) No inheritance of url: "..url..."
setting. It means, that child state won't have the url
set with the same value as parent. Both values are independent.
2) There is implicit url
concatenation. Child state url
(in address bar, not the setting) is built from all its ancestors url
.
So, the documentation is correct. This example is just for play ... It shows what we know. Child has different url
setting then parent. Child state url
in address bar is build from its url
setting - prefixed with parent(s) url
// NON abstract
.state('parent1', {
abstract: false,
url: "/parent1",
templateUrl: 'tpl.html',
})
.state('parent1.child1', {
url: "/child1",
templateUrl: 'tpl.html',
})
// abstract
.state('parent2', {
abstract: true,
url: "/parent2",
templateUrl: 'tpl.html',
})
.state('parent2.child2', {
url: "/child2",
templateUrl: 'tpl.html',
})
url in href:
non abstract
<a href="#/parent1">
<a href="#/parent1/child1">
abstract
<a href="#/parent2"> - cannot navigate there - is abstract
<a href="#/parent2/child2">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With