Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ilikerobots/398b34f5c5a2f5bcf36aea6d3e63ae9b to your computer and use it in GitHub Desktop.

Select an option

Save ilikerobots/398b34f5c5a2f5bcf36aea6d3e63ae9b to your computer and use it in GitHub Desktop.
typedef String TitleNamingFunction(ComponentInstruction c);
@Injectable()
class TitleSetService {
TitleNamingFunction nameStrategy;
Router _router;
Title _title;
TitleSetService(this._router, this._title) {
nameStrategy = _defaultNameStrategy;
_router.subscribe(_setTitleFromRoute);
}
Future<Null> _setTitleFromRoute(String url) async {
//identify component instruction from routed url
ComponentInstruction compInst = (await _router.recognize(url))?.component;
if (compInst != null) {
_title.setTitle(nameStrategy(compInst));
}
}
String _defaultNameStrategy(ComponentInstruction compInst) {
return compInst.routeName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment