wouterb
1
I want to do something simular to this, bind params when routing.
routes: [
{
path: ‘/manage-company/’,
url: ‘manage-company.html?idc=:idc’,
}
mainView.router.navigate({url:’/manage-company/’, query: {idc: 18}});
What is the correct way to do this?
vousys
2
I use this
{
path: '/pages/:entidad/listado', // ej: href="/pages/frutas/listado"
componentUrl: './pages/listados.html',
options: {
context: {
entidad: '{{entidad}}', // Envia por param: "frutas"
},
},
},
where :entidad is a parameter
and in your html, you can retrive it like this:
<template>
<div class="page listados page-{{$route.params.entidad}}" data-name="{{$route.params.entidad}}">
<div class="navbar">
wouterb
3
Yes but how do i use this in my example if i want router.navigate to route to specified URL?
vousys
4
this should be your route (try it please!)
{
path: '/manage-company/:idc/',
componentUrl: './manage-company.html',
options: {
context: {
idc: '{{idc}}',
},
},
},
the “:idc” refers to a dynamic parameter
and to navigate:
app.router.navigate("/manage-company/"+ idc + '/',{
route:{
context: { idc: idc }
}
});
wouterb
6
It’s not working:
Uncaught ReferenceError: idc is not defined
vousys
7
you should replace IDC with your local var o data.
As I see in the example of your first post, you put “18”
wouterb
8
I got it working 
mainView.router.routes = [{
path: ‘/manage-company/:idc/’,
url: ‘manage-company.html?idc={{idc}}’
}];
mainView.router.navigate('/manage-company/18/');
1 Like
This is so simple, very handy and should be mention in documentation!
1 Like