[SOLVED] Using params in router


#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?


#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">

#3

Yes but how do i use this in my example if i want router.navigate to route to specified URL?


#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 }
              }
            });

#5

Great i will try that :slight_smile:


#6

It’s not working:

Uncaught ReferenceError: idc is not defined


#7

you should replace IDC with your local var o data.
As I see in the example of your first post, you put “18”


#8

I got it working :slight_smile:

mainView.router.routes = [{
path: ‘/manage-company/:idc/’,
url: ‘manage-company.html?idc={{idc}}’

	    }];

	    mainView.router.navigate('/manage-company/18/');

#9

This is so simple, very handy and should be mention in documentation!