router icon indicating copy to clipboard operation
router copied to clipboard

Invoking Context.next() causes not rendering component in subroute

Open MalwareX95 opened this issue 6 years ago • 0 comments

Hello. I'm not certian whether what I found is bug or not, from your sample i've assumed that component from subpath is rendered, beside in my code router also behave oddly because action method from subroute is invoked but component is not rendered.

sample from your page:

const recordUrlVisit = context => {
    const visitedPath = context.pathname; // get current path
    urlToNumberOfVisits[visitedPath] = (urlToNumberOfVisits[visitedPath] || 0) + 1;
    document.getElementById('stats').innerHTML =
      `Statistics on URL visits: ${JSON.stringify(urlToNumberOfVisits, null, 2)}}`;
    return context.next(); // pass to the next route in the list
  };

  const router = new Router(document.getElementById('outlet'));
  router.setRoutes([
    {path: '/', component: 'x-home-view'},
    {
      path: '/users',
      action: recordUrlVisit, // will be triggered for all children
      children: [
        {path: '/', component: 'x-user-list'},
        {path: '/:user', component: 'x-user-profile'}
      ]
    },
  ]);

my code:

router.setRoutes([
    {
        path: '/',
        component: 'navigation-layout',
        action:  (ctx, command) => {
            return ctx.next();
            //const next = await ctx.next();
            //store.dispatch(something(next.route.name))
            //return next;
        },
        children: [
          { 
            path: '/', 
            name: 'home',
            component: 'home-view', 
            action: () => {
              console.log('home')
              import('./views/home')
            },
          },
          {
            path: '/announce',
            name: 'announce',
            component: 'announce-view',
            action: () => { 
                console.log('1234')
                import('./views/announce')
            }
        }]
    },

MalwareX95 avatar Feb 29 '20 20:02 MalwareX95