Angular2Dart Router.currentInstruction not being set


I am writing a simple paging widget in Angular2Dart. The component has a route method that should get the current route, update parameters, and navigate. I’m not sure I am doing this correctly, but in this current implementation, I am using router.currentInstruction. The problem is router.currentInstruction is null.

Here is the component (simplified for this question):

import 'package:angular2/angular2.dart';
import 'package:angular2/router.dart';
import 'package:angular_components/angular_components.dart';

  selector: 'paging-component',
  templateUrl: 'paging_component.html',
  styleUrls: const [
  directives: const [
class PagingComponent {

  final RouteParams routeParams;
  final Router _router;

  PagingComponent(this.routeParams, this._router);

  void _route([Map<String, String> updatedParams]) {
    var existingParams = new Map.from(routeParams.params);
    if (updatedParams != null) {
    var currentRoute = _router.currentInstruction.component.routeName;
    _router.navigate([currentRoute, existingParams]);


You can get the currentInstruction using

void routerOnActivate(next, prev) {
  print('Activating ${next.routeName} ${next.urlPath}');

there might be other ways. I can’t tell if _router.currentInstruction in your example should work. It might depend on where route(...) is being called from.

See also

Answered By – Günter Zöchbauer

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *