2

this is my app.js

import Index from './index'
import WeatherEng from './weatherEng'
import WeatherAr from './weatherAr'

import {Router, hashHistory, Route} from 'react-router'
ReactDOM.render(
  <Router history={hashHistory}>
    <Route path="/" component={Index}>
        <Route path="Arabic" component={WeatherAr}/>
        <Route path="english" component={WeatherEng}/>
    </Route>
  </Router>, document.queryString('.container')
)

and this index .js

import React  from 'react';
import ReactDOM from 'react-dom';
import $ from "min-jquery";
import axios from "axios";
import { render } from 'react-dom'
import WeatherEng from './weatherEng'
import WeatherAr from './weatherAr'
import {Link} from 'react-router';


const urlP=`http://localhost:3000/blah`;

class App extends React.Component {
constructor(props){
    super(props);
    this.state={ 
      imagedayA:[],
      imagenightA:[]

      };
  }
   componentDidMount() {
     axios.get(urlP)
            .then(function (response) {
              console.log(response.data,"this is response")
              this.setState({
                imagedayA:response.data.today.iconday,
                imagenightA:response.data.today.iconnight,
              })  
          }.bind(this))
            .catch(function (response) {
              console.log(response);
          });
      }
  render(){
    return (
       <div>
            <button><Link to="WeaAr">another</Link></button>
            <button><Link to="WeaEng">English</Link></button>
            <div>{this.props.children}</div> 

        </div>

    );
  };
}


render(<App/>,document.querySelector('.container'));

https://i.stack.imgur.com/GwcYH.jpg I got new errors Uncaught TypeError: document.queryString is not a function(…) Warning: Failed propType: Invalid prop component supplied to Route. acctually the main idea is i want when click on another button it give yo component and when click on english button it move me to english component

flower
  • 989
  • 4
  • 16
  • 34

1 Answers1

0

I think your Link contains wrong to path, try this:

<button><Link to="Arabic">another</Link></button>
<button><Link to="english">English</Link></button>

And one more thing you are already rendering your App component through React Router, no need to render it again in App component by this:

render(<App/>,document.querySelector('.container')); Remove this line.

Use this code:

import Index from './index'
import WeatherEng from './weatherEng'
import WeatherAr from './weatherAr'


ReactDOM.render(
  <Router history={hashHistory}>
    <Route path="/" component={Index}>
        <Route path="Arabic" component={WeatherAr}/>
        <Route path="english" component={WeatherEng}/>
    </Route>
  </Router>, document.getElementById('container')
)

Put this line in html file: <div id='container'></div>

Mayank Shukla
  • 100,735
  • 18
  • 158
  • 142
  • did u imported `ReactDOM` in app.js file, because in ur code its not present ?? if not use these lines: `import React from 'react'; import ReactDOM from 'react-dom';` – Mayank Shukla Feb 04 '17 at 19:33
  • ya i import it now its same thing – flower Feb 04 '17 at 19:35
  • no its not working re open the link that i put it u ll see the errors – flower Feb 04 '17 at 20:17
  • now this is app.js import Index from './index' import WeatherEng from './weatherEng' import WeatherAr from './weatherAr' import ReactDOM from 'react-dom'; import React from 'react'; import {Router, hashHistory, Route} from 'react-router' ReactDOM.render( ,document.querySelector('.container') ) – flower Feb 04 '17 at 20:22
  • use this: `document.getElementById('container')` and put this line in html file: `
    `
    – Mayank Shukla Feb 04 '17 at 20:22
  • and this is index.js which main component import React from 'react'; import ReactDOM from 'react-dom'; import $ from "min-jquery"; import axios from "axios"; import { render } from 'react-dom' import WeatherEng from './weatherEng' import WeatherAr from './weatherAr' import {Link} from 'react-router'; const urlP=`http://localhost:3000/simplyamman/api/amman`; class App extends React.Component { constructor(props){ super(props); this.state={ imagedayA:[], imagenightA:[] }; } – flower Feb 04 '17 at 20:23
  • this complete for index.js componentDidMount() { axios.get(urlP) .then(function (response) { this.setState({ imagedayA:response.data.today.iconday, imagenightA:response.data.today.iconnight }) }.bind(this)) .catch(function (response) { }); } render(){ return (
    {this.props.children}
    ) }}render(,document.querySelector('.container'));
    – flower Feb 04 '17 at 20:23
  • sorry my mistake, got confused with name index and app, try the updated code it will work :) delete the last two comments, got ur point :) – Mayank Shukla Feb 04 '17 at 20:26
  • let me know if u need any help in this. – Mayank Shukla Feb 04 '17 at 20:42
  • i try these and its give me components but data is empty how i can pass data that i put it in this.state – flower Feb 04 '17 at 21:04
  • and this in componts how i try get data

    {this.props.tempdayA}°

    by this.props
    – flower Feb 04 '17 at 21:05
  • how i can pass the data – flower Feb 05 '17 at 07:19
  • its not a good practice to pass the complete object data from link, u can pass some property name but dont pass the object data, use the concept of Store, redux of flux architecture, save your data their and fetch the data from store :) – Mayank Shukla Feb 05 '17 at 09:46
  • check these links: http://stackoverflow.com/questions/30115324/pass-props-in-link-react-router and http://stackoverflow.com/questions/31168014/pass-object-through-link-in-react-router, i think your original problem has been solved, plz mark the ans as correct :) – Mayank Shukla Feb 05 '17 at 09:52