Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No registered route was found to handle '/videos/1234'. #26

Closed
stemuk opened this issue Nov 23, 2017 · 11 comments
Closed

No registered route was found to handle '/videos/1234'. #26

stemuk opened this issue Nov 23, 2017 · 11 comments

Comments

@stemuk
Copy link

stemuk commented Nov 23, 2017

I tried to implement routing in my application with fluro, however I had several problems following the 'getting started' guide on Github.

My implementation is rather simple, since the new GestureDetector( onTap: () { _handleTap(context); }, .... )
is supposed to manually push the route with void _handleTap(BuildContext context) { router.navigateTo(context, "/videos/1234", transition: TransitionType.native); }.

The router is initialized according to the getting started example, but once I test the app the error

No registered route was found to handle '/videos/1234'.

What else is needed in order to push the route, or am I doing something wrong?

@lukef
Copy link
Collaborator

lukef commented Nov 23, 2017

Can you share the code where you register / create the routes?

@stemuk
Copy link
Author

stemuk commented Nov 23, 2017

Yes, sure.

final router = new Router();
var usersHandler = new Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return new VideosScreen(params["id"]);
});
void defineRoutes(Router router) {
  router.define("/videos/:id", handler: usersHandler);
}
void _handleTap(BuildContext context) {
  router.navigateTo(context, "/videos/1234",
      transition: TransitionType.native);
}

The full file is here.

Edit: I am relatively new to flutter so I have a hard time understanding what 'Buildcontext context' is supposed to do and how to use it correctly.

@lukef
Copy link
Collaborator

lukef commented Nov 23, 2017

Will take a look

@lukef
Copy link
Collaborator

lukef commented Nov 23, 2017

I tested here and it seems to be working ok. But, let me shoot over some suggestions to try and if it doesn't work we can take another look.

If you're only using one router in your app (which probably most people do) you can try creating a class specifically for routing responsibilities. For example:

import 'package:fluro/fluro.dart';

class AppRouter {

  static final AppRouter _instance = new AppRouter._internal();
  final Router _router = new Router();  // global router

  factory AppRouter() {
    return _instance;
  }
  AppRouter._internal();

  // singleton
  Router router() { return _router; }

  void configureRoutes() {
    _router.define("/videos/:id", handler: videoDetailHandler);
  }
}

Then inside your Home class you can add (or inside initState if you make it stateful):

  Home() : super() {
    final appRouter = new AppRouter();
    appRouter.configureRoutes();
    appRouter.router().printTree();
  }

Adding it to the constructor or initState will mean that it wont be re-created / reconfigured each time build() is called.

Finally, at the point when you want to navigate to the route you can use:

new AppRouter().router().navigateTo(context, "/videos/1234");

Let me know how it goes.

@stemuk
Copy link
Author

stemuk commented Nov 24, 2017

Thanks a lot for your help, will try it out in a few hours and get back to you how it worked. Thanks again!

@stemuk
Copy link
Author

stemuk commented Nov 24, 2017

I implemented fluro following your advice, but I still have the error "Undefined name 'context'." for the part that manually pushes the route

new AppRouter().router().navigateTo(context, "/videos/1234");

How do I define the variable and what type of parameter is required? Thanks again for your help!

@lukef
Copy link
Collaborator

lukef commented Nov 25, 2017

Can you share the code again? That's almost certainly a regular dart issue. It means that context, as a variable, is undefined.

@stemuk
Copy link
Author

stemuk commented Nov 25, 2017

Sure. I already expected it to be a dart issue, but I somehow am unable to fix it. The code is here, and the line in question is 69, where the 'context' in void _handleTap() { new AppRouter().router().navigateTo(context, "/videos/1234"); } seems to be undefined.

@lukef
Copy link
Collaborator

lukef commented Nov 25, 2017

Your _handleTap method is declared at a global level and is not contained inside a class. The BuildContext object is not defined at that scope. You should move _handleTap into BookList and pass context to it via void _handleTap(BuildContext context). You will need to swap out your onTap to be something like:

onTap: () { _handleTap(context) }

If you're new to flutter then I highly recommend jumping on the flutter/flutter Gitter chat. Everyone there is super helpful and we hang out there as well. URL: https://gitter.im/flutter/flutter.

@lukef
Copy link
Collaborator

lukef commented Nov 25, 2017

Going to close this issue because it seems like it's working normally. I'll work to expand on the examples a little in the future.

@lukef lukef closed this as completed Nov 25, 2017
@stemuk
Copy link
Author

stemuk commented Nov 26, 2017

It works now, thanks a lot for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants