-
Notifications
You must be signed in to change notification settings - Fork 270
Closed
Description
Story
- define parent module with params in the route, like
/something/:id
- define child module with simple routes like
/first
and/second
- navigate to first route with
Modular.to.pushNamed('/something/123/first');
- inside child module navigate to another page with
Modular.link.pushNamed('/second')
Current behavior
Child module route second
receive args like {'id':':id'}
Expected behavior
Child module should receive args like {'id': '123'}
Code example
Tap on Navigate inside module with "link"
to reproduce the issue
Example
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
void main() => runApp(ModularApp(module: AppModule()));
class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// set your initial route
initialRoute: "/",
navigatorKey: Modular.navigatorKey,
// add Modular to manage the routing system
onGenerateRoute: Modular.generateRoute,
);
}
}
class AppModule extends MainModule {
@override
List<Bind> get binds => [];
@override
List<ModularRouter> get routers => [
ModularRouter('/', child: (_, __) => MyHomePage()),
ModularRouter('/sample/:id', module: SampleModule()),
];
@override
Widget get bootstrap => AppWidget();
}
class SampleModule extends ChildModule {
@override
List<Bind> get binds => [];
@override
List<ModularRouter> get routers => [
ModularRouter('/', child: (_, args) => SamplePage(id: args.params['id'])),
ModularRouter('/list', child: (_, args) => SampleChildPage(id: args.params['id'])),
];
static Inject get to => Inject<SampleModule>.of();
}
class MyHomePage extends StatelessWidget {
final String title = 'Test';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// The title text which will be shown on the action bar
title: Text(title),
),
body: Center(
child: Column(
children: [
Text(
'Hello, World!',
),
ElevatedButton(
child: Text('Navigate to child module'),
onPressed: () {
Modular.to.pushNamed('/sample/123/');
},
),
],
),
),
);
}
}
class SamplePage extends StatelessWidget {
final String id;
const SamplePage({this.id});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sample page'),
),
body: Center(
child: Column(
children: [
Text(
'Sample page with id: $id',
),
ElevatedButton(
child: Text('Navigate inside module with "link"'),
onPressed: () {
Modular.link.pushNamed('/list');
},
),
ElevatedButton(
child: Text('Navigate inside module with "to"'),
onPressed: () {
Modular.to.pushNamed('/sample/$id/list');
},
),
],
),
),
);
}
}
class SampleChildPage extends StatelessWidget {
final String id;
const SampleChildPage({this.id});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sample Child page'),
),
body: Center(
child: Text(
'Sample Child page with id: $id',
),
),
);
}
}
Metadata
Metadata
Assignees
Labels
No labels