Skip to content

How to activate nested components with ids from the entire chain of nested routes. #136

@adrian-moisa

Description

@adrian-moisa

After implementing the demo example I have reached a roadblock. In the intro example the routes seem to have a 1 to 1 relation between route and action.

const routes = [
    {
        path: '', // optional
        action: () => `<h1>Home</h1>`,
    },
    {
        path: '/posts',
        action: () => console.log('checking child routes for /posts'),
        children: [
            {
                path: '', // optional, matches both "/posts" and "/posts/"
                action: () => `<h1>Posts</h1>`,
            },
            {
                path: '/:id',
                action: (context) => `<h1>Post #${context.params.id}</h1>`,
            },
        ],
    },
];

I am used to building nested components that have a router outlet (Angular 2) or match components (React). For example I would have a nesting like this:

 <chapter-cmp>
    <h1>Chapter title</h1>
    ...

    <lesson>
        <h1>Lesson title</h1>
        ...
    </lesson>

</chapter-cmp>
<sidebar>
    <p>Open almost all the time except for a few routes</p>
</sidebar>

How do I feed the corresponding data for each layer of the app? Currently I am not aware how can I get the ids from parents of nested routes without having to create monolitic routes like these path: '/:course/:chapter/:lesson'. I thought that I can just fire actions in the state store that will be received by the components. But than what if I move to another section of the app where I need to tear-down some components and instantiate others. '/blog/:category/:posts'`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions