コード例 #1
0
ファイル: index.js プロジェクト: Xuefeng-Zhu/Masonry-Layout
const render = () => {
  const { pathname, search, hash } = window.location
  const location = `${pathname}${search}${hash}`

  // We need to have a root route for HMR to work.
  const createRoutes = require('../common/routes/root').default
  const routes = createRoutes(store)

  // Pull child routes using match. Adjust Router for vanilla webpack HMR,
  // in development using a new key every time there is an edit.
  match({ routes, location }, () => {
    // Render app with Redux and router context to container element.
    // We need to have a random in development because of `match`'s dependency on
    // `routes.` Normally, we would want just one file from which we require `routes` from.
    ReactDOM.render(
      <Provider store={store}>
        <Router routes={routes} history={browserHistory} key={Math.random()} />
      </Provider>,
      container
    )
  })

  return browserHistory.listen(location => {
    // Match routes based on location object:
    match({ routes, location }, (error, redirectLocation, renderProps) => {
      if (error) console.log(error)
      // Get array of route handler components:
      const { components } = renderProps

      // Define locals to be provided to all lifecycle hooks:
      const locals = {
        path: renderProps.location.pathname,
        query: renderProps.location.query,
        params: renderProps.params,

        // Allow lifecycle hooks to dispatch Redux actions:
        dispatch
      }

      // Don't fetch data for initial route, server has already done the work:
      if (window.INITIAL_STATE) {
        // Delete initial data so that subsequent data fetches can occur:
        delete window.INITIAL_STATE
      } else {
        // Fetch mandatory data dependencies for 2nd route change onwards:
        trigger('fetch', components, locals)
      }

      // Fetch deferred, client-only data dependencies:
      trigger('defer', components, locals)
    })
  })
}
コード例 #2
0
ファイル: Browse.js プロジェクト: inevity/minio
 componentWillMount() {
   const {dispatch} = this.props
   // Clear out any stale message in the alert of Login page
   dispatch(actions.showAlert({
     type: 'danger',
     message: ''
   }))
   if (web.LoggedIn()) {
     web.ListBuckets()
       .then(res => {
         let buckets
         if (!res.buckets)
           buckets = []
         else
           buckets = res.buckets.map(bucket => bucket.name)
         if (buckets.length) {
           dispatch(actions.setBuckets(buckets))
           dispatch(actions.setVisibleBuckets(buckets))
           if (location.pathname === minioBrowserPrefix || location.pathname === minioBrowserPrefix + '/') {
             browserHistory.push(utils.pathJoin(buckets[0]))
           }
         }
       })
   }
   this.history = browserHistory.listen(({pathname}) => {
     let decPathname = decodeURI(pathname)
     if (decPathname === `${minioBrowserPrefix}/login`) return // FIXME: better organize routes and remove this
     if (!decPathname.endsWith('/'))
       decPathname += '/'
     if (decPathname === minioBrowserPrefix + '/') {
       return
     }
     let obj = utils.pathSlice(decPathname)
     if (!web.LoggedIn()) {
       dispatch(actions.setBuckets([obj.bucket]))
       dispatch(actions.setVisibleBuckets([obj.bucket]))
     }
     dispatch(actions.selectBucket(obj.bucket, obj.prefix))
   })
 }
コード例 #3
0
ファイル: client.js プロジェクト: serge-ivanov-nk/test-app
browserHistory.listen(location => {

  // Match routes based on location object:
  match({ routes, location }, (error, redirectLocation, renderProps) => {
    // Get array of route handler components:
    const { components } = renderProps;

    // Define locals to be provided to all lifecycle hooks:
    const locals = {
        path: renderProps.location.pathname,
        query: renderProps.location.query,
        params: renderProps.params,

        // Allow lifecycle hooks to dispatch Redux actions:
        dispatch,
      };

    // Don't fetch data for initial route, server has already done the work:
    if (window.INITIAL_STATE) {
      // Delete initial data so that subsequent data fetches can occur:
      delete window.INITIAL_STATE;
    } else {
      // Fetch mandatory data dependencies for 2nd route change onwards:
      trigger('fetch', components, locals);
    }

    // Fetch deferred, client-only data dependencies:
    trigger('defer', components, locals);
  });
});
コード例 #4
0
ファイル: client.js プロジェクト: LASkuma/redux-boilerplate
    <Provider store={store}>
        <Router history={browserHistory} routes={routes} />
    </Provider>
  ), document.getElementById('root'))
})

browserHistory.listen(location => {
  match({ routes, location }, (error, redirectLocation, renderProps) => {
    const { components } = renderProps

    const locals = {
      path: renderProps.location.pathname,
      query: renderProps.location.query,
      params: renderProps.params,
      dispatch
    }

    // Don't fetch data for initial route, server has already done the work:
    if (window.INITIAL_STATE) {
      // Delete initial data so that subsequent data fetches can occur:
      delete window.INITIAL_STATE;
    } else {
      // Fetch mandatory data dependencies for 2nd route change onwards:
      trigger('fetch', components, locals);
    }

    // Fetch deferred, client-only data dependencies:
    trigger('defer', components, locals);
  })
})