themeteorchef / base

A starting point for Meteor apps.
http://themeteorchef.com/base
MIT License
689 stars 253 forks source link

Add nested routes for documents and move auth to top-level #225

Closed thearabbit closed 7 years ago

thearabbit commented 7 years ago

Could config onEnter={ authenticate } for all? Instead of this:

<Route name="documents" path="/documents" component={ Documents } onEnter={ authenticate }/>
<Route name="newDocument" path="/documents/new" component={ NewDocument } onEnter={ authenticate }/>
themeteorchef commented 7 years ago

@thearabbit I'll have to take a look. Off-hand you can only do onEnter on groups of routes applying to all of them.

thearabbit commented 7 years ago

Thanks for your reply. Could you example on base router?

themeteorchef commented 7 years ago

@thearabbit sure, flagging this as a refactor. For the time being, here's an example:

<Route path="/documents" onEnter={ authenticate }>
  <Route name="newDocument" path="new" component={ NewDocument } />
  <Route name="editDocument" path=":_id/edit" component={ EditDocument } />
  <Route name="viewDocument" path=":_id" component={ ViewDocument } />
</Route>
thearabbit commented 7 years ago

Thanks again. I will try soon.

thearabbit commented 7 years ago

Now, I tried but have problem with Document List Page

// Default
<Route name="documents" path="/documents" component={ Documents } onEnter={ authenticate }/>
-------
// Nested
<Route path="/documents" onEnter={ authenticate }>
  <Route name="newDocument" path="new" component={ NewDocument } />

Please help me.

themeteorchef commented 7 years ago

@thearabbit make sure to follow the example I posted above. When nesting a route, you need to close the parent route after the child, like this:

<Route path="/documents" onEnter={ authenticate }>
  <IndexRoute name="documents" component={ Documents } />
  <Route name="newDocument" path="new" component={ NewDocument } />
</Route>

Edit: Just realized you need to add the <IndexRoute /> component for the documents list.

thearabbit commented 7 years ago

Oh, Look great. Very thanks 👍