Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning an element from the action method does not put anything in DOM #342

Closed
manolo opened this issue Aug 9, 2019 · 2 comments · Fixed by #344
Closed

Returning an element from the action method does not put anything in DOM #342

manolo opened this issue Aug 9, 2019 · 2 comments · Fixed by #344
Assignees
Labels
bug Something isn't working hilla
Milestone

Comments

@manolo
Copy link
Member

manolo commented Aug 9, 2019

Try this code, route / works and puts a div element in the hosting outlet, but /1 and /2 do not display anything.

const routes = [
   {
       path: '/',
       component: 'div',
       children: [
           {
               path: '/1',
               action: () => {
                   const e = document.createElement('div');
                   e.textContent = 'foo-1';
                   return e;
               }
           }
       ]
   },
   {
       path: '/2',
       action: async () => {
           const e = document.createElement('div');
           e.textContent = 'foo-2';
           return e;
       }
   }
];

Notes:

  • this API o similar is necessary for CCDM.
  • consider that action might be async
@vlukashov vlukashov added the bug Something isn't working label Aug 9, 2019
@platosha
Copy link
Contributor

platosha commented Aug 9, 2019

Here is a workaround for now:

action: (context, commands) => {
  const e = commands.component('div');
  e.textContent = 'foo-1';
  return e;
}

UPD: works for sync and async actions too. Navigating to /2 results in Page not found because of some other reason, presumably #307

@platosha
Copy link
Contributor

As discussed in the team, the router should support actions that return elements created with document.createElement and other APIs, not limiting the users to commands.component.

@vlukashov vlukashov added this to the CCDM MVP milestone Aug 12, 2019
@platosha platosha self-assigned this Aug 12, 2019
platosha added a commit that referenced this issue Aug 12, 2019
manolo pushed a commit that referenced this issue Aug 14, 2019
…xt.component (#344)

* fix(router): enable rendering HTMLElement created without using context.component

Fixes #342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants