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

Named param being removed from URL #115

Open
cliveportman opened this issue May 25, 2021 · 3 comments
Open

Named param being removed from URL #115

cliveportman opened this issue May 25, 2021 · 3 comments

Comments

@cliveportman
Copy link

cliveportman commented May 25, 2021

With the following routes, if I visit /courses/sewing-course/lesson-1 it changes the URL to /courses/sewing-course (i.e. it's removing the :id parameter from the URL. How do I stop this? The correct compnent (Lesson) is being used and I can still access the named parameters :slug and :id, it's just that I want the URL preserved.

  {
    name: '/',
    component: Dashboard, 
    layout: PrivateLayout
  },
  {
    name: 'courses',
    layout: PrivateLayout,
    component: '',
    nestedRoutes: [
      {
        name: ':slug',
        component: Course
      },
      {
        name: ':slug/:id',
        component: Lesson
      }
    ],
  },```
@jorgegorka
Copy link
Owner

Hi @cliveportman

Named params are optional not mandatory so having two routes with only named params is not expected. What I would suggest is having only one route and then inside the route rendering Course or Lesson depending on id being present or not.

    {
        name: ':slug/:id',
        component: Details
      }

This link may also help. #88

@jorgegorka
Copy link
Owner

This should work as well:

    name: '/',
    component: Dashboard, 
    layout: PrivateLayout
  },
  {
    name: 'courses',
    layout: PrivateLayout,
    component: '',
    nestedRoutes: [
      {
        name: ':slug',
        component: Course,
        nestedRoutes: [
               {
                  name: 'lesson/:id',
                  component: Lesson
                }
        ]
      },
    ],
  },```

@cliveportman
Copy link
Author

This should work as well:

    name: '/',
    component: Dashboard, 
    layout: PrivateLayout
  },
  {
    name: 'courses',
    layout: PrivateLayout,
    component: '',
    nestedRoutes: [
      {
        name: ':slug',
        component: Course,
        nestedRoutes: [
               {
                  name: 'lesson/:id',
                  component: Lesson
                }
        ]
      },
    ],
  },```

With this one, would the URL be /courses/sewing-course/lesson/640 ? I get 404 with that setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants