logo
down
shadow

react-router tutorial not working on mac


react-router tutorial not working on mac

By : Y.Mharrek
Date : November 20 2020, 11:01 PM
I wish this helpful for you Try to change the port to something else with the command webpack-dev-server --port 3000 --inline --content-base
You can also substitute the npm start script in the package.json with that line.
code :


Share : facebook icon twitter icon
React-Router 1.0.0-rc4 - dynamic router - params not working

React-Router 1.0.0-rc4 - dynamic router - params not working


By : Pink Anderson
Date : March 29 2020, 07:55 AM
This might help you SOLVED
Nearly a day later, I solved this and the mistake I made was so stupid and so blatantly obvious I cannot believe I did not see it.
code :
<Route path="Inventory" component="Inventory">
   <Route path="Inventory/All-Vehicles" component="Inventory" />
</Route>
  <li id={ this.props.item.id }
      ......
      onClick={ this.routeHandler.bind(this, { newLinkTo } ) } >
    <span className="">{ this.props.item.title }</span>
      // get the children
      <div>{ this.fetchSubMenu(this.props.item) }</div>
  </li>
  <li id={ this.props.item.id }
      ......
  >
    <Link to={ newLinkTo } className="">{ this.props.item.title }</Link>
      // get the children
      <div>{ this.fetchSubMenu(this.props.item) }</div>
  </li>
Redux & React-Router: Dynamic Router Not Working

Redux & React-Router: Dynamic Router Not Working


By : bahadır kınalı
Date : March 29 2020, 07:55 AM
With these it helps If anyone is interested, here is a dynamic react-router with redux.
[The world has too many todos examples, be nice if I wasn't the one always coming up with the real world examples.]
code :
import 'babel-core/polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import Routes from './router/routes';
// redux
import { Provider } from 'react-redux';
import configureStore from './store/configureStore';
// styles
import './index.css';   

// Setting up entire state 'schema' at inception
const store = configureStore();

ReactDOM.render(
  <Provider store={ store }>
    <Routes />
  </Provider>,
  document.getElementById('root')
);
import React, { Component, PropTypes } from 'react';
import { Router, Route, IndexRoute } from 'react-router';

// redux
import { connect } from 'react-redux';
import { fetchNavItemsIfNeeded } from '../actions/nav-items-actions';

// history
import createBrowserHistory from 'history/lib/createBrowserHistory';
const history = createBrowserHistory();

import App from '../containers/app/App';
import Home from '../containers/home/Home';
import NotFound from '../containers/misc/NotFound';

class Routes extends Component {

  constructor() {
    super();
    this.state = {
      routes: []
    };
  }

  fetchMenuSystem(data) {
    const self = this;
    const currRoutesState = this.state.routes;
    const routes = data === undefined ? this.props.navItems : data;

    routes.map((route) => {
      // set paths up first
      let currPaths = [];
      if (route.paths !== undefined) {
        currPaths = route.paths;
      } else {
        currPaths.push(route.linkTo);
      }
      // Components - first check for ecomMods
      let currComponent;
      if (route.ecomMod !== undefined) {
        currComponent = require('../containers/' + route.ecomMod);
        // clear out currPath if this is an ecom Module
        // and start a new currPaths array
        currPaths = [];
        if (route.parentId === null) {
          currPaths.push(route.ecomMod);
        } else {
          currPaths.push(route.ecomMod + '/:id');
        }
      } else {
        currComponent = require('../containers/' + route.component);
      }

      currPaths.map((currPath, idx) => {
        const props = { key: idx, path: currPath, component: currComponent };
        currRoutesState.push(<Route { ...props } />);
      });

      if (route.childNodes !== undefined) {
        self.fetchMenuSystem(route.childNodes);
      }
    });
    return currRoutesState;
  }

  componentDidMount() {
    const { dispatch } = this.props;
    const clientId = '7B3E7eWWPizd11n';
    dispatch(fetchNavItemsIfNeeded(clientId));
  }

  render() {
    if (!this.props.navItems) return <div>Loading ...</div>;
    return (
      <Router history={ history }>
        <Route path="/" component={ App }>
          <IndexRoute component={ Home }/>
          { this.fetchMenuSystem() }
          <Route path="*" component={ NotFound }/>
        </Route>
      </Router>
    );
  }
}

function mapStateToProps(state) {
  const { navItemsPerClient } = state;
  if (!navItemsPerClient) {
    return {
      isFetching: false,
      didInvalidate: false,
      navItems: [],
      error: null
    };
  }

  return {
    error: navItemsPerClient.error,
    isFetching: navItemsPerClient.isFetching,
    didInvalidate: navItemsPerClient.didInvalidate,
    navItems: navItemsPerClient.navItems
  };
}

Routes.propTypes = {
  dispatch: PropTypes.func.isRequired,
  navItems: PropTypes.array
};

export default connect(mapStateToProps)(Routes);
import 'isomorphic-fetch';
import { checkStatus, parseJSON } from './utils';

export const INVALIDATE_NAV_ITEMS = 'INVALIDATE_NAV_ITEMS';   
export const NAV_ITEMS_REQUEST = 'NAV_ITEMS_REQUEST';
export const NAV_ITEMS_SUCCESS = 'NAV_ITEMS_SUCCESS';
export const NAV_ITEMS_FAILURE = 'NAV_ITEMS_FAILURE';

export function invalidateNavItems() {
  return {
    type: INVALIDATE_NAV_ITEMS
  };
}

function navItemsRequest() {
  return {
    type: NAV_ITEMS_REQUEST
  };
}

function navItemsSuccess(payload) {
  return {
    type: NAV_ITEMS_SUCCESS,
    navItems: payload.navItems
  };
}

function navItemsFailure(error) {
  return {
    type: NAV_ITEMS_FAILURE,
    error
  };
}  

export function fetchNavItems(clientId) {
  const API_URL = (`../data/${clientId}/navigation/navigation.json`);
  return dispatch => {
    dispatch(navItemsRequest());
    return fetch(API_URL)
      .then(checkStatus)
      .then(parseJSON)
      .then(json => dispatch(navItemsSuccess(json)))
      .catch(function(error) {
        const response = error.response;
        if (response === undefined) {
          dispatch(navItemsFailure(error));
        } else {
          parseJSON(response)
            .then(function(json) {
              error.status = response.status;
              error.statusText = response.statusText;
              error.message = json.message;
              dispatch(navItemsFailure(error));
            });
        }
      });
  };
}

function shouldFetchNavItems(state) {
  // Check cache first
  const navItems = state.navItemsPerClient;
  if (!navItems || navItems.length === undefined) {
    // Not cached, should fetch
    return true;
  }

  if (navItems.isFetching) {
    // Shouldn't fetch since fetching is running
    return false;
  }

  // Should fetch if cache was invalidate
  return navItems.didInvalidate;
}

export function fetchNavItemsIfNeeded(clientId) {
  return (dispatch, getState) => {
    if (shouldFetchNavItems(getState())) {
      return dispatch(fetchNavItems(clientId));
    }
  };
}
export function checkStatus(response) {
  if (!response.ok) {   // (response.status < 200 || response.status > 300)
    const error = new Error(response.statusText);
    error.response = response;
    throw error;
  }
  return response;
}

export function parseJSON(response) {
  return response.json();
}
import { 
         INVALIDATE_NAV_ITEMS, NAV_ITEMS_REQUEST, 
         NAV_ITEMS_SUCCESS, NAV_ITEMS_FAILURE 
       } from '../actions/nav-items-actions';

function navItems(state = {
  isFetching: false,
  didInvalidate: false,
  navItems: [],
  error: null
}, action) {
  switch (action.type) {
  case INVALIDATE_NAV_ITEMS:
    return Object.assign({}, state, {
      didInvalidate: true
    });
  case NAV_ITEMS_REQUEST:
    return Object.assign({}, state, {
      isFetching: true,
      didInvalidate: false
    });
  case NAV_ITEMS_SUCCESS:
    return Object.assign({}, state, {
      isFetching: false,
      didInvalidate: false,
      navItems: action.navItems,
      error: null
    });
  case NAV_ITEMS_FAILURE:
    return Object.assign({}, state, {
      isFetching: false,
      didInvalidate: false,
      error: action.error
    });
  default:
    return state;
  }
}

export function navItemsPerClient(state = { }, action) {
  switch (action.type) {
  case INVALIDATE_NAV_ITEMS:
  case NAV_ITEMS_REQUEST:
  case NAV_ITEMS_SUCCESS:
  case NAV_ITEMS_FAILURE:
    return navItems(state, action);
  default:
    return state;
  }
}
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import auth from '../reducers/auth-reducer';
import { navItemsPerClient } from '../reducers/nav-items-reducer';

const logger = createLogger();
const reducer = combineReducers(
  {
    auth,
    navItemsPerClient
  }
);

const createStoreWithMiddleware = applyMiddleware(
  thunkMiddleware,
  logger
)(createStore);

export default function configureStore(initialState) {
  return createStoreWithMiddleware(reducer, initialState);
}
{
  "incomplete_results": false,
  "navItems": [
    {
      "linkTo": "/about",
      "component": "about/About",
      "childNodes": [
        {
          "linkTo": "/proforma",
          "component": "about/ProForma"
        }
      ]
    },
    {
      "linkTo": "/login",
      "component": "login/Login"
    },
    {
      "linkTo": "/none",
      "component": "misc/RestrictPage",
      "childNodes": [
        {
          "linkTo": "/users",
          "component": "user/UsersPage"
        },
        {
          "linkTo": "/repos",
          "component": "repo/ReposPage"
        }
      ]
    }
  ]
}
"dependencies": {
    "body-parser": "^1.14.1",
    "classnames": "^2.2.0",
    "express": "^4.13.3",
    "fixed-data-table": "^0.5.0",
    "history": "^1.13.0",
    "isomorphic-fetch": "^2.1.1",
    "lodash": "^3.10.1",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "^4.0.0",
    "react-router": "^1.0.2",
    "redux": "^3.0.4",
    "redux-logger": "^2.0.4",
    "redux-thunk": "^1.0.0"
  },
  "devDependencies": {
    "babel": "^5.8.29",
    "babel-core": "^5.8.33",
    "babel-eslint": "^4.1.5",
    "babel-loader": "^5.3.2",
    "eslint": "^1.9.0",
    "eslint-config-airbnb": "^1.0.0",
    "eslint-loader": "^1.1.1",
    "eslint-plugin-react": "^3.8.0",
    "file-loader": "^0.8.4",
    "raw-loader": "^0.5.1",
    "redbox-react": "^1.1.1",
    "rimraf": "^2.4.3",
    "stats-webpack-plugin": "^0.2.2",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.6",
    "webpack": "^1.12.4",
    "webpack-dev-middleware": "^1.2.0",
    "webpack-hot-middleware": "^2.4.1"
  }
url refresh nor working as expected with create-react-app and react-router-redux on DEV

url refresh nor working as expected with create-react-app and react-router-redux on DEV


By : markamaze
Date : March 29 2020, 07:55 AM
help you fix your problem A refresh should maintain the same pathname, not reset to root.
I'm not sure why you would want to go to the root on refresh, but the way that you would accomplish that would be to manually navigate when your application is loading.
code :
import { createBrowserHistory } from 'history'

const history = createBrowserHistory()
history.replace('/')

ReactDOM.render((
  <Provider>
    <ConnectedRouter history={history}>
      ...
    </ConnectedRouter>
  </Provider>
), holder)
Changing to custom domain on Github Pages causes create-react-app with react-router to stop working

Changing to custom domain on Github Pages causes create-react-app with react-router to stop working


By : user2263045
Date : March 29 2020, 07:55 AM
With these it helps Turns out create-react-app docs actually highlight this problem. Github pages doesn't play well with BrowserRouter. Theres a sort of hack in the documents here that worked swimmingly for me.
React Native: no style on views works when I use react-router / react-router-navigation

React Native: no style on views works when I use react-router / react-router-navigation


By : Johan Neidenmark
Date : March 29 2020, 07:55 AM
this will help I solved it myself. I am now using React Native Router Flux. I am still learning and trying out.
Related Posts Related Posts :
  • React's setState(), data mutation for nested structures, why not modify state directly?
  • Dispatching an action in a specific component based on a reducer state change
  • using React component library without @types
  • How to parse a string with variables into a react component?
  • in React + Redux, when should use response.json()
  • How to move reactjs components into seperate page when using CDN
  • create-react-app and d3 - Why is d3 undefined?
  • Using lodash in shouldComponentUpdate
  • Deploying build to production using express server which i compiled using webpack -p
  • How to write interceptor in react-redux?
  • XJS value should be either an expression or a quoted XJS text
  • How to display 12months with material-ui
  • Reordering a sequence of objects in a normalised Redux data structure
  • Markdown in React with Typescript
  • Is it an efficient practice to add new epics lazily inside react-router onEnter hooks?
  • React: Execute some check before render
  • Set component's props dynamically
  • Webpack + Babel: Couldn't find preset "es2015" relative to directory
  • What is the right way to fire an action with siblings state in React/Flux?
  • React-server failling without error
  • Add Server Side Rendering to create-react-app
  • Should I store static configuration in redux?
  • State is not updating in componentWillMount
  • How to envoke a method on a react component (Amcharts-React)
  • HOC vs Wrapper in render function
  • Need to find the way to slice this array to show only n customers
  • Do I need to specify the key prop in this case and how would I do that then?
  • rror: FactoryMethod.render(): A valid React element (or null) must be returned.
  • How to pass a function instead of string as a prop to a component
  • what is wrong with 'this.setState'
  • Use ref to invoke instance methods
  • How to keep two separate categories under the same list, but keep other categories separated per se?
  • Stateless function components cannot hav refs
  • Update array object in React Redux reducer
  • PropTypes React Native is not an object
  • Jest test fail: SyntaxError: Unexpected token <
  • React Redux form and connect syntax
  • Can anyone provide an example on React-Redux Jest testing?
  • React server side renderer omits setState callback function?
  • Bootstrap Checkbox Not Toggling
  • distorted map image when using react-leaflet
  • react-scripts Invalid Host header
  • remove text from button that created in loop
  • how to limit redux-form's fieldArray field.push to 3
  • Referencing state for loop rendered elements in react
  • React Native update multidimensional state value on switch press
  • Draft.js - How to trim contents
  • how to syncState to firebase with re-base?
  • React component test with enzyme
  • Under what circumstances React class component will be constructed many times?
  • react-native 0.49 brackets after base class
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com