Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Decouple Fragment matching from predefined routes #139

Closed
andykais opened this issue Feb 16, 2017 · 3 comments
Closed

Decouple Fragment matching from predefined routes #139

andykais opened this issue Feb 16, 2017 · 3 comments

Comments

@andykais
Copy link

from what I can see, react-little-router exceeds with little applications. If I am building a larger application I want to organize my routes in a single routes file which includes the components routes are mapped to, or even break up a routes into multiple files.

using your library, I have this helper so I can use a single file for my routes

// createRoutes.js
import React from 'react'
import { RelativeFragment as Fragment } from 'redux-little-router'

export const createRoutes = (routes) => {
  const routesObject = {}
  routes.forEach((routeObj) => {
    routesObject[routeObj.path] = { title: 'placeholder' }
  })
  return routesObject
}

export const createRouteComponents = (routes) => {
  
  const routeComponents = routes.map(route => {
    const RouteComponent = route.component
    return (
      <Fragment key={route.path} forRoute={route.path}>
        <RouteComponent/>
      </Fragment>
    )
  })
  return (
    <App>
      { routeComponents }
    </App>
  )
}
// routes.js
import HomePage from 'containers/HomePage'
import ErrorPage from 'containers/ErrorPage'

export default [
  {
    path: '/',
    component: HomePage
  },
  {
    path: '/error',
    component: ErrorPage
  }
]
// index.js
const RouteFragments = createRouteComponents(routes)
const RouteObject = createRoutes(routes)

const renderComponent = () => (
  <RouterProvider store={store}>
    { RouteFragments }
  </RouterProvider>
)

ReactDOM.render(
  renderComponent(),
  root
)

would you consider including something like this? Something where routes dont need to be defined in both a routes object and in each Fragment? It makes a react-router app much easier to reason about. If that same logic can be applied without react-router that would be awesome!

@tptee tptee changed the title reorganize routes object Decouple Fragment matching from predefined routes Mar 23, 2017
@tptee
Copy link
Contributor

tptee commented Mar 23, 2017

Been thinking about this for a while–I think we can make this happen in a minor release soon 👍

@tptee
Copy link
Contributor

tptee commented Jun 18, 2017

Check out #189Fragment matching is decoupled from static routes. Even better, you can just ditch static routes altogether if you don't want/need them!

@tptee
Copy link
Contributor

tptee commented Jun 22, 2017

This is done in v14.0.0-0

@tptee tptee closed this as completed Jun 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants