I'm playing around with the new angular router and wanted to try out a use case where I have a component and a nested component.
Below there's the JavaScript code I wrote to define the two components and the routes:
angular.module('app', ['ngNewRouter'])
.controller('AppController', function ($router) {
$router.config([
{
path: '/parent',
component: 'parent'
}
]);
})
.controller('ParentController', function ($router) {
this.name = 'Parent component';
$router.config([
{
path: '/child',
component: 'child'
}
]);
})
.controller('ChildController', function () {
this.name = 'Child component';
})
.config(function ($componentLoaderProvider) {
$componentLoaderProvider.setTemplateMapping(function (compName) {
return compName + '.html';
});
});
And the HTML part:
<!-- index.html -->
<body ng-controller="AppController as app">
<a ng-link="parent">Go to parent</a>
<div ng-viewport></div>
</body>
<!-- parent.html -->
{{ parent.name }}<br/>
<a ng-link="child">Show child</a>
<div ng-viewport></div>
<!-- child.html -->
{{ child.name }}
Here's a Plunker containing the code above: http://plnkr.co/edit/yWCFgXQI491EYvIldjyR
Based on this code I have the following questions/issues:
- If I go to the lowest level (#/parent/child) and then hit refresh, the parent and child components are not shown anymore. The route is not restored even though the URL still is the same. Do I need to renavigate or do something to restore the page's state? This is a very basic feature to be able to bookmark URLs.
- If I go to the lowest level (#/parent/child) and then click on the Go to parent link, the URL is correctly set to #/parent but the child component is still visible.