Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue-router: navigate to nested state/route by name and params

How can I navigate to a child state using $router.push?

My routes:

const routes = [
  {
    path: "/customers", name: 'Customers',
    components: {content: CustomersMain},
    props: {header: true, content: false},
    children: [
      {
        path: '',
        component: CustomerDetailsEmpty
      },
      {
        path: ':id',
        name: 'CustomerDetails',
        component: CustomerDetails
      }
    ]
  }
];

How can I navigate to CustomerDetails with an id param set using $router.push?

like image 734
Alexander Zeitler Avatar asked Oct 24 '18 20:10

Alexander Zeitler


People also ask

How do I create a dynamic route Vue?

Adding dynamic routes in VueUpdate the router/index. js file with the new route in the routes array. Remember to include the import for the Post component. Restart your app and head to localhost:8080/post/dynamic-routing in your browser.

Can we define multiple router outlets in a component Vue?

Instead of having one single outlet in your view, you can have multiple and give each of them a name. A router-view without a name will be given default as its name. A working demo of this example can be found here.


1 Answers

This did the trick:

this.$router.push({ name: `CustomerDetails`, params: {id} });
like image 142
Alexander Zeitler Avatar answered Oct 10 '22 07:10

Alexander Zeitler