initRouter method
void
initRouter(
- RoutingConfig routingConfig,
- String initialRoutePath
)
Implementation
void initRouter(RoutingConfig routingConfig, String initialRoutePath) {
// Use PathUrlStrategy for removing # from URLs.
// setUrlStrategy(PathUrlStrategy()); // <<<< ADD THIS LINE
routingConfigVN = ValueNotifier<RoutingConfig>(routingConfig);
router = GoRouter.routingConfig(
navigatorKey: fco.globalNavigatorKey,
debugLogDiagnostics: false,
initialLocation: initialRoutePath,
routingConfig: routingConfigVN,
// onException: (_, GoRouterState state, GoRouter router) {
// router.go('/404', extra: state.uri.toString());
// },
// when page not found by router
errorBuilder: (context, state) {
String matchedLocation = state.matchedLocation;
// var param = state.pathParameters;
// implicit built-in page
if (matchedLocation == '/pages') {
if (fco.canEditContent()) {
return Pages();
} else {
return AlertDialog(
title: Container(
alignment: Alignment.center,
padding: EdgeInsets.all(40),
child: fco.coloredText(
'Viewing the Page list:\nYou must be signed in as an editor !',
color: Colors.red,
),
),
);
}
}
// may have already been created (incl content callout snippets)
// final snippetNames = appInfo.snippetNames;
// bool dynamicPageExists = snippetNames.contains(matchedLocation);
// if (dynamicPageExists) {
// EditablePage.removeAllNodeWidgetOverlays();
// // fco.dismiss('exit-editMode');
// final snippetName = matchedLocation;
// final rootNode = SnippetTemplateEnum.empty.clone()
// ..name = snippetName;
// SnippetRootNode.loadSnippetFromCacheOrFromFBOrCreateFromTemplate(
// snippetName: snippetName,
// templateSnippetRootNode: rootNode,
// );
// final dynamicPage = EditablePage(
// key: GlobalKey(), // provides access to state later
// routePath: matchedLocation,
// child: SnippetPanel.fromSnippet(
// panelName: "dynamic panel",
// snippetName: snippetName,
// scName: null,
// key: ValueKey<String>(snippetName),
// ),
// );
// return dynamicPage;
// }
// // page doesn't exist yet
// // editor can ask to create it
// if (canEditContent()) {
// return AlertDialog(
// title: Text('Page "$matchedLocation" does not Exist !'),
// content: SingleChildScrollView(
// child: ListBody(
// children: const <Widget>[Text('Want to create it now ?')],
// ),
// ),
// actions: <Widget>[
// TextButton(
// child: Text('Yes, Create page $matchedLocation'),
// onPressed: () {
// final String destUrl = matchedLocation;
// EditablePage.removeAllNodeWidgetOverlays();
// // fco.dismiss('exit-editMode');
// // bool userCanEdit = canEditContent.isTrue;
// final snippetName = destUrl;
// final rootNode = SnippetTemplateEnum.empty.clone()
// ..name = snippetName;
// SnippetRootNode.loadSnippetFromCacheOrFromFBOrCreateFromTemplate(
// snippetName: snippetName,
// templateSnippetRootNode: rootNode,
// ).then((_) {
// afterNextBuildDo(() {
// // SnippetInfoModel.snippetInfoCache;
// router.push(destUrl);
// // router.go('/');
// });
// });
// },
// ),
// TextButton(
// child: const Text('Cancel'),
// onPressed: () {
// context.go('/');
// },
// ),
// ],
// );
// }
// dynamic user-editable page
/* if (fco.appInfo.userEditablePages.contains(matchedLocation)) {
final String destUrl = matchedLocation;
EditablePage.removeAllNodeWidgetOverlays();
// fco.dismiss('exit-editMode');
// bool userCanEdit = canEditContent.isTrue;
final snippetName = destUrl;
final rootNode = SnippetTemplateEnum.empty.clone()
..name = snippetName;
SnippetRootNode.loadSnippetFromCacheOrFromFBOrCreateFromTemplate(
snippetName: snippetName,
templateSnippetRootNode: rootNode,
).then((_) {
afterNextBuildDo(() {
// SnippetInfoModel.snippetInfoCache;
router.push(destUrl);
// router.go('/');
});
});
}
*/
return AlertDialog(
title: const Text('Page does not Exist !'),
content: ElevatedButton(
onPressed: () {
context.go('/');
},
child: const Text('go back'),
),
);
},
observers: [GoRouterObserver()],
);
if (router != null) {
List<String> routePaths = [];
parseRouteConfig(routePaths, router!.configuration.routes);
populatePageList();
}
}