reapp / reapp-routes

Simple route DSL
MIT License
34 stars 13 forks source link

how to have tree structure in routes? #5

Open kiang opened 9 years ago

kiang commented 9 years ago

Just want to organize folder structure and willing to be reflected in routes. Like...

components/articles/Index.jsx => /articles/index components/articles/View.jsx => /articles/View

The snippet I've tried not working as expected:

router(require,
  route('home', '/',
    route('sub')
  ),
  route('articles',
    route('index'),
    route('view')
  )
);
natew commented 9 years ago

It structures it like so:

components/Articles components/articles/View

rather than using Index, though that would be a nice option. I'd be open to a pull request.

kiang commented 9 years ago

with the routes like

router(require,
  route('home', '/',
    route('sub')
  ),
  route('articles',
    route('view')
  )
);

The button

<Button onTap={() => this.router().transitionTo('articles')}>

returned error messages: Error: Invariant Violation: Cannot find a route named "articles"

natew commented 9 years ago

I believe you'd need articles to be inside of home:

router(require,
  route('home', '/',
    route('articles',
      route('view', '/articles/:id')
    )
  ),
);

Which would give you /articles and /articles/1

wuichen commented 9 years ago

I'm kind of confused of how to have a tree structured routes, can you put out some examples of it?

I have made a button in sub route, <Button onTap={() => this.router().transitionTo('sub1')}> Go to sub1 view

The url changes, but the page doesnt c

router(require, route('home', '/', route('sub', route('sub1') ) ) );

my file structure

app -- components ---- home ------ sub.jsx ------ home.jsx ------ sub -------- sub1

Tjorriemorrie commented 8 years ago

I don't understand this router at all:

Warning: No route matches path "/". Make sure you have somewhere in your routes

router(require,
    route('auth', '/foo'),
    route('home', '/',
        route('sub')
    )
);