JavaScript Nested routes (/:foo/:bar) with parameters do not render, why?

So, I'm not sure if I should've structured my app different or if I'm doing something fundamentally wrong. I'm a bit confused, but let's explain first things first.

In the first navigation level, there are 4 pages - and for every page, there is a detail page.

  • Home
  • Article-Category 1
    • Detail page
  • Article-Category 2
    • Detail page
  • Article-Category 3
    • Detail page

The article category pages are exactly the same. They all hold a list (<ul><li><Link></Link></li><li>...</ul>) of 10-20 articles, so I actually just created one component, the article category component.

To make this work, the main navigation of the app holds <Link>'s which have a param called page passed to the article category component. Depending on this parameter, the view looks for the articles in an array and uses another component to render them as a list.

The article array itself holds the name of the the article and the parameter article name, f.e. this-is-an-article. I'm passing the article name parameter to the detail component which looks, depending on this and the page parameter, for the correct article.

Okay, so I hope this is clear. Now, this is my react-router configuration:

export default (
    <Route path="/" handler={App}>
        {/* Home */}
        <DefaultRoute name="home" handler={Home}/>

        {/* Page */}
        <Route name="category" path=":category" handler={Category}>
            <Route name="category.article" path=":article" handler={Article} />
        </Route>

        {/* Not found */}
        <NotFoundRoute handler={NotFound} />
    </Route>
);

.. but this doesn't work. If I click on an article link which has the correct parameters, nothing happens - well, the URL changes, but nothing else.. and the navigation menu item stays active, which is good. I at least know the parameters are correct because when I change my route confgiruation below /* Page */ to this:

    <Route name="category" path=":category" handler={Category} />
    <Route name="category.article" path=":category/:article" handler={Article} />

it works, but in my main navigation, the naivgation item isn't active anymore when I'm on an article (detail) page, I guess because it's not a child route anymore, so the configuration above this should be the correct one, but it doesn't work..

Below, there are the relevant components and their code + the content array/object. Mind you, the code shown is without any import's (I'm using ES6 with Babel through Webpack), but of course there are some.

Article component (renders the article itself)

let Article = React.createClass({
    getInitialState() {
        return {
            article: this.props.params.article,
            category: this.props.params.category
        }
    },
    componentWillReceiveProps(nextProps) {
        this.setState({
            article: nextProps.params.article,
            category: nextProps.params.category
        })
    },
    render() {
        let content = this._getContent();

        return (
            <div className="page_content page_content-article">
                <ArticleHeader />
                {content}
            </div>
        )
    },
    _getContent() {
        let item;

        for(item of ContentStore[this.state.category]) {
            if(item.name === this.state.article) {
                return item.content;
            }
        }
    }
});

Category component (renders the article list with the ArticleList component which just renders with the category and article params and is the same for each category)

let Index = React.createClass({
    getInitialState() {
        return {
            category: this.props.params.category
        };
    },
    componentWillReceiveProps(nextProps) {
        this.setState({
            category: nextProps.params.category
        });
    },
    render() {

        return (
            <div className={'page_content page_content-' + this.state.category}>
                <ArticleList articles={this._getArticles()} category={this.state.category} />
            </div>
        )
    },
    _getArticles() {
        return ContentStore[this.state.category];
    }
});

App component

let App = React.createClass({
    render() {
        return (
            <div className="page">
                <RouteHandler />
                <Navigation />
            </div>
        )
    }
});

PageStore (Example of the data - this renders the main navigation)

PageStore: [
    {
        id: 1,
        title: 'Home',
        iconClass: 'home',
        linkTo: 'home',
        params: null
    },
    {
        id: 2,
        title: 'Category 1',
        iconClass: 'foo',
        linkTo: 'category',
        params: {
            category: 'foo',
        }
    },
    ...
]

ContentStore (example of the data - this renders the article lists and the detail view as it has it's content)

ContentStore: {
    // "foo" is the category name
    foo: [
        {
            id: 1,
            name: 'article-1',
            linkText: 'Article 1',
            content: (
                <div>
                    lorem ipsum...
                </div>
            )
        },

    ]
} 

I have two questions:

  • What am I missing and how do I make this work?
  • SHOULD I actually make this work even if I can or is there a better way? I did it this way because the category pages and the detail page do not have any differences except the content, which comes (yet) from a simple array.

I also ask if I actually should do this because well.. I never see nested routes where both, the parent and the child, have props. Maybe this is actually a bad thing to do.. I'm not sure. If you need any more information, I'm happy to provide it and thanks you in advance.

Answer:1

I'd like to build a website with a full height whatever the user's screen. Scroll is impossible, everything is shown in the page. I tried something like : <body> <div class="header"> ...

I'd like to build a website with a full height whatever the user's screen. Scroll is impossible, everything is shown in the page. I tried something like : <body> <div class="header"> ...

  1. full page height css
  2. full page height bootstrap
  3. full page height javascript
  4. full page height
  5. full page height div bootstrap
  6. full page height js
  7. full page height header
  8. page full height html
  9. iframe full page height
  10. get full page height javascript
  11. body full page height css
  12. flex full page height
  13. flexbox full page height
  14. get full page height jquery
  15. bootstrap full page height container
  16. jquery full page height
  17. get full page height
  18. full page auto height
  19. full page responsive height
  20. get full page height css

Html looks like this: <input class="car-type-input" name="carType[bmw]".../> How to get a variable in javascript which contains bmw using jQuery? Html CANT be changed! Current javascript: ...

Html looks like this: <input class="car-type-input" name="carType[bmw]".../> How to get a variable in javascript which contains bmw using jQuery? Html CANT be changed! Current javascript: ...

  1. variable complex
  2. variable complex pdf
  3. variable complex numbers
  4. variable complex function
  5. variable complex sentences
  6. variable complex root
  7. variable complex method

I saw this documentation on Google Developer site, they show me how to format hAxis label but only label with number format. I don't know how to format the labels that use date format. Here is my ...

I saw this documentation on Google Developer site, they show me how to format hAxis label but only label with number format. I don't know how to format the labels that use date format. Here is my ...

  1. format axis label
  2. format axis label matplotlib
  3. format axis label in excel
  4. format axis label matlab
  5. tableau format axis label
  6. c# chart format axis label
  7. amcharts format axis label
  8. d3 format axis label
  9. ggplot format axis label
  10. highcharts format axis label
  11. highcharts y axis label format
  12. chartjs axis label format
  13. highchart x axis label format
  14. devexpress chart axis label format
  15. gnuplot axis label format
  16. pandas plot axis label format
  17. pivot chart axis label format
  18. pyplot axis label format
  19. matplotlib x axis label format
  20. chartjs y axis label format

I'm trying to clear my input fields after an onClick event. I'm using react-bootstrap library and while there is a getValue() method, there is not setValue(value) method. I've stumbled upon this ...

I'm trying to clear my input fields after an onClick event. I'm using react-bootstrap library and while there is a getValue() method, there is not setValue(value) method. I've stumbled upon this ...

  1. react bootstrap clear form
  2. react-bootstrap clear
  3. react bootstrap typeahead clear input
  4. react bootstrap table clear selected
  5. react bootstrap input clear button
  6. react-bootstrap-typeahead clear
  7. react bootstrap table clear filter
  8. react bootstrap formcontrol clear