diff --git a/flutter_modular/lib/src/routers/route_link.dart b/flutter_modular/lib/src/routers/route_link.dart index d7a823b9..cb26a26c 100644 --- a/flutter_modular/lib/src/routers/route_link.dart +++ b/flutter_modular/lib/src/routers/route_link.dart @@ -23,44 +23,30 @@ class RouteLink extends IModularNavigator { void pop([T result]) => Modular.navigator.pop(result); @override - Future popAndPushNamed( - String routeName, - {TO result, - Object arguments}) => - Modular.navigator.popAndPushNamed(_checkpath(routeName), - result: result, arguments: arguments); + Future popAndPushNamed(String routeName, {TO result, Object arguments}) => + Modular.navigator.popAndPushNamed(_checkpath(routeName), result: result, arguments: arguments); @override - void popUntil(bool Function(Route) predicate) => - Modular.navigator.popUntil(predicate); + void popUntil(bool Function(Route) predicate) => Modular.navigator.popUntil(predicate); @override - Future push(Route route) => - Modular.navigator.push(route); + Future push(Route route) => Modular.navigator.push(route); @override Future pushNamed(String routeName, {Object arguments}) => Modular.navigator.pushNamed(_checkpath(routeName), arguments: arguments); @override - Future pushNamedAndRemoveUntil( - String newRouteName, bool Function(Route) predicate, + Future pushNamedAndRemoveUntil(String newRouteName, bool Function(Route) predicate, {Object arguments}) => - Modular.navigator.pushNamedAndRemoveUntil( - _checkpath(newRouteName), predicate, - arguments: arguments); + Modular.navigator.pushNamedAndRemoveUntil(_checkpath(newRouteName), predicate, arguments: arguments); @override - Future pushReplacementNamed( - String routeName, - {TO result, - Object arguments}) => - Modular.navigator.pushReplacementNamed(_checkpath(routeName), - result: result, arguments: arguments); + Future pushReplacementNamed(String routeName, + {TO result, Object arguments}) => + Modular.navigator.pushReplacementNamed(_checkpath(routeName), result: result, arguments: arguments); @override - Future pushReplacement( - Route newRoute, - {TO result}) => + Future pushReplacement(Route newRoute, {TO result}) => Modular.navigator.pushReplacement(newRoute, result: result); @override @@ -69,14 +55,29 @@ class RouteLink extends IModularNavigator { @required WidgetBuilder builder, bool barrierDismissible = true, }) => - Modular.navigator.showDialog( - builder: builder, - child: child, - barrierDismissible: barrierDismissible); + Modular.navigator.showDialog(builder: builder, child: child, barrierDismissible: barrierDismissible); String _checkpath(String routeName) { + // Add a slash to the begin of route name if haven't routeName = routeName[0] == '/' ? routeName : '/$routeName'; - var newPath = "$modulePath$routeName".replaceAll('//', '/'); + + // Split main path to a list + var modulePathList = modulePath.split('/'); + + // While the route given by user starts with backward token string + while (routeName.startsWith('/..')) { + // Remove last item from main path + modulePathList.removeLast(); + + // remove this 3 chars from begin of user given route + routeName = routeName.substring(3); + } + + // Transform the list to string again + final modulePathComp = modulePathList.reduce((value, element) => "$value/$element"); + + var newPath = "$modulePathComp$routeName".replaceAll('//', '/'); + return newPath; }