React Router won't render components properly









up vote
0
down vote

favorite
1












I am trying to use render two components at once. There's two routes: /:id/ and /:id/:pokemonId/. When I hit the /:id/ route, everything works as it should, but when I go to /:id/:pokemonId/ no styles are loaded, but the content shows up. There is also an infinite axios request happening (I don't know if these are related). Ideally, both routes will load with the /:id/ content on the bottom and the /:pokemonId/ content at the top.






import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)





In my components, I am calling the functions props.updatePokemon() and props.findPokemonById() and then displaying it in a very basic way, so I don't think the code there changes anything. It is being called immediately if that matters.



Why are the stylesheets rendering in one route and not the other? Is it related to getting infinite requests?










share|improve this question



















  • 1




    should put in getPokemon.call(this) inside componentDidMount() instead imo
    – Matt Pengelly
    Nov 10 at 17:38










  • Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
    – Michael Koska
    Nov 10 at 17:48










  • @MichaelKoska read the official docs first, specifically the component API ;)
    – c-chavez
    Nov 11 at 14:04















up vote
0
down vote

favorite
1












I am trying to use render two components at once. There's two routes: /:id/ and /:id/:pokemonId/. When I hit the /:id/ route, everything works as it should, but when I go to /:id/:pokemonId/ no styles are loaded, but the content shows up. There is also an infinite axios request happening (I don't know if these are related). Ideally, both routes will load with the /:id/ content on the bottom and the /:pokemonId/ content at the top.






import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)





In my components, I am calling the functions props.updatePokemon() and props.findPokemonById() and then displaying it in a very basic way, so I don't think the code there changes anything. It is being called immediately if that matters.



Why are the stylesheets rendering in one route and not the other? Is it related to getting infinite requests?










share|improve this question



















  • 1




    should put in getPokemon.call(this) inside componentDidMount() instead imo
    – Matt Pengelly
    Nov 10 at 17:38










  • Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
    – Michael Koska
    Nov 10 at 17:48










  • @MichaelKoska read the official docs first, specifically the component API ;)
    – c-chavez
    Nov 11 at 14:04













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I am trying to use render two components at once. There's two routes: /:id/ and /:id/:pokemonId/. When I hit the /:id/ route, everything works as it should, but when I go to /:id/:pokemonId/ no styles are loaded, but the content shows up. There is also an infinite axios request happening (I don't know if these are related). Ideally, both routes will load with the /:id/ content on the bottom and the /:pokemonId/ content at the top.






import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)





In my components, I am calling the functions props.updatePokemon() and props.findPokemonById() and then displaying it in a very basic way, so I don't think the code there changes anything. It is being called immediately if that matters.



Why are the stylesheets rendering in one route and not the other? Is it related to getting infinite requests?










share|improve this question















I am trying to use render two components at once. There's two routes: /:id/ and /:id/:pokemonId/. When I hit the /:id/ route, everything works as it should, but when I go to /:id/:pokemonId/ no styles are loaded, but the content shows up. There is also an infinite axios request happening (I don't know if these are related). Ideally, both routes will load with the /:id/ content on the bottom and the /:pokemonId/ content at the top.






import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)





In my components, I am calling the functions props.updatePokemon() and props.findPokemonById() and then displaying it in a very basic way, so I don't think the code there changes anything. It is being called immediately if that matters.



Why are the stylesheets rendering in one route and not the other? Is it related to getting infinite requests?






import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)





import React, Component from "react";
import
BrowserRouter as Router,
Route
from "react-router-dom";
import PokecardList from "./Pokecard_List";
import PagelinksList from "./Pagelinks_List";
import PokecardInfo from "./Pokecard_Info";

const axios = require("axios");


class Main extends Component
constructor(props)
super(props);
this.state =
pokemon: ,
selectedPage: null,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`,
pageInfo: null,
selectedPokemon: null
;

getPokemon.call(this)


render()
return (
<Router>
<div>
<Route
path="/:id/:pokemonId/"
render=(props) => <PokecardInfo
selectedPokemon=this.state.selectedPokemon
findPokemonById=() =>
axios.get(`$this.state.url?name=$props.match.params.pokemonId`)
.then(( data ) =>
this.setState(
selectedPokemon: data.data
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<Route
path="/:id/"
render=(props) => <PokecardList
pokemon=this.state.pokemon
updatePokemon=() =>
axios.get(`$this.state.url?page=$props.match.params.id`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: props.match.params.id
)
)
.catch((error) =>
console.log(error);
)

...props
/>
/>
<div>
<PagelinksList

pageInfo=this.state.pageInfo
/>
</div>
</div>
</Router>
);



//put into another file
function getPokemon()
axios.get(`$this.state.url`)
.then(( data ) =>
this.setState(
pokemon: data.data,
selectedPage: data.meta.current_page,
pageInfo: data.meta,
url: `https://intern-pokedex.myriadapps.com/api/v1/pokemon`
);
)
.catch((error) =>
console.log(error);
)






javascript reactjs react-router






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 17:37









Minderov

4541615




4541615










asked Nov 10 at 17:34









Michael Koska

186




186







  • 1




    should put in getPokemon.call(this) inside componentDidMount() instead imo
    – Matt Pengelly
    Nov 10 at 17:38










  • Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
    – Michael Koska
    Nov 10 at 17:48










  • @MichaelKoska read the official docs first, specifically the component API ;)
    – c-chavez
    Nov 11 at 14:04













  • 1




    should put in getPokemon.call(this) inside componentDidMount() instead imo
    – Matt Pengelly
    Nov 10 at 17:38










  • Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
    – Michael Koska
    Nov 10 at 17:48










  • @MichaelKoska read the official docs first, specifically the component API ;)
    – c-chavez
    Nov 11 at 14:04








1




1




should put in getPokemon.call(this) inside componentDidMount() instead imo
– Matt Pengelly
Nov 10 at 17:38




should put in getPokemon.call(this) inside componentDidMount() instead imo
– Matt Pengelly
Nov 10 at 17:38












Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
– Michael Koska
Nov 10 at 17:48




Thanks, I will look into that. First time using react so this is tutorial project and I had no idea that existed.
– Michael Koska
Nov 10 at 17:48












@MichaelKoska read the official docs first, specifically the component API ;)
– c-chavez
Nov 11 at 14:04





@MichaelKoska read the official docs first, specifically the component API ;)
– c-chavez
Nov 11 at 14:04


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241630%2freact-router-wont-render-components-properly%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241630%2freact-router-wont-render-components-properly%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric