Question

I'm trying to make a forum.

On client-side I have this :

void initRouter() {
    var router = new Router();

    router.root
        ..addRoute(name: 'register', path: '/register', enter: (e) => showRegister(e, router), leave: leaveRegister)
        ..addRoute(name: 'login', path: '/login', enter: (e) => showLogin(e, router), leave: leaveLogin)
        ..addRoute(name: 'forum_general', path: '/forum', enter: (e) => showForum(e, router))
        ..addRoute(
            name: 'forum_target',
            path: '/forum/:nForum',
            mount: (router) =>
            router
                ..addRoute(
                name: 'subforum_general',
                path: '/subforum',
                enter: (e) => showSubForum(e, router))
                ..addRoute(
                name: 'subforum_target',
                path: '/subforum/:subForum',
                mount: (router) =>
                router
                    ..addRoute(
                    name: 'subject_general',
                    path: '/subject',
                    enter: (e) => showSubForum(e, router))
                    ..addRoute(
                    name: 'subject_target',
                    path: '/subject/:nSubject',
                    enter: (e) => showSubForum(e, router))))
        ..addRoute(name: 'logout', path: '/logout', enter: (e) => showLogout(e, router))
        ..addRoute(defaultRoute: true, name: 'index', path: '/index', enter: showIndex);
    router.listen();
}

When I go on a simple path (like /forum) it work. But when I add some information (like forum/test) the router don't catch the URL...

Even if I use this, ..addRoute(name: 'subforum_general', path: '/forum/:nForum', enter: (e) => showSubForum(e, router)), it doesn't work..

Any idea ?

Était-ce utile?

La solution

I can't really find much documentation on the router package (assuming that's what you're using), and its GitHub repo is marked as "build failing" :/

There's another routing package called route which is maintained by the Dart Authors, which I've use a little, and seems to work well. If you can't get router to do what you need, I would definitely consider giving it a shot.

https://pub.dartlang.org/packages/route

main() {
  var router = new Router()
    ..addHandler(new UrlPattern(r'/article/(\d+)'), showArticle)
    ..listen();
}

void showArticle(String path) {
  var articleId = articleUrl.parse(req.path)[0];
  // show article page with loading indicator
  // load article from server, then render article
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top