kitbagjs / router

A type safe router for vuejs
MIT License
131 stars 1 forks source link

retain parent params when routing between children? #186

Closed stackoverfloweth closed 1 month ago

stackoverfloweth commented 1 month ago

Given these routes from the stackblitz repo

const routes = createRoutes([
  {
    name: 'home',
    path: '/',
    component: HomeView,
  },
  {
    name: 'settings',
    path: '/settings',
    query: 'search=[?search]',
    component: () => import('../views/SettingsView.vue'),
    children: createRoutes([
      {
        name: 'profile',
        path: '/profile',
        component: () => import('../views/SettingsProfileView.vue'),
      },
      {
        name: 'keys',
        path: '/keys',
        query: query('sort=[?sort]', { sort: sortParam }),
        component: () => import('../views/SettingsKeysView.vue'),
      },
    ])
  },
]);

Notice how settings has a query param for search and is a parent to profile and keys. If I set a value on this param and then navigate to a child the param value is lost. This is true for both using a router-link to navigate as well as router.push.

https://github.com/kitbagjs/router/assets/6098901/603aa824-b6a4-4949-862f-cba485f2de7d