This question is related to this question
Routing: get notified about parameter updates without reloading the view
I have a view with a grid-view (generated using ng-repeat
).
The routing parameter recId
specifies which row is made current initially.
The view has navigation buttons (forward backward) to select the current record. A click in a row also makes this row the current row.
This kind of (view internal) navigation doesn't make use of AngularDarts routing functionality after the initial load of the view.
The back/forward buttons don't reflect navigation inside the view.
As soon as I change the current record inside the view, the browser URL is out of sync.
If I change the browser URL each time the user uses a navigation action, the view get's reloaded. This makes development more complicated and leads to ugly reloads of the view (which is WIP - see linked question).
What is the best/correct way to keep application state and browser URL (history) in sync.
Update
How do I configure the router so that a click on one of this generated links updates the URL in the browser but doesn't reload the view. (It should be possible to create a bookmark for the currently selected record.)
The code is a bit outdated but I didn't work on this project since I asked this question.
The router configuration
library my_prototype.routing;
import 'package:angular/angular.dart';
import '../services/injectable.dart';
@InjectableService()
class AppRouteInitializer {
call(Router router, ViewFactory views) {
router.root
..addRoute(
name: 'table',
path: '/:entityId/table/:recId',
enter: views('view/dynamic_table.html')
)
..addRoute(
name: 'default_view',
defaultRoute: true,
enter: (_) =>
router.go('form',
{
'entityId': '',
'rec': '-1'
},
replace: true));
}
}
index.html contains beside Dart/AngularDart boilerplate only
<ng-view></ng-view>
The view component contains this constructor
@NgComponent(
selector: 'dynamic-table',
publishAs: 'ctrl',
template: r'''
<div ng-repeat="rec in ctrl.records">
<a href="/{{entityId}}/table/{{rec.id}}">{{rec.name}}</a>
<div>''')
class DynamicTableComponent {
HttpService _httpService;
RouteProvider _routeProvider;
String entityId;
List<SomeRecord> records = [];
DynamicTableComponent(this._routeProvider, this._httpService) {
_log.fine('DynamicFormComponent');
entityId = _routeProvider.parameters['entityId'];
... render table
}
}
I got a notification today about a pull request that might be about this topic