Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Angular Routing Variable types

I'm having trouble making some window size detection logic work in the routing file of my angular project. I'm using Angular 4, and when I write some basic logic to detect the document size (which tells me the size of the HTML page) everything works. But when I try to action this in the form of placing a variable in the path route, i keep getting error "TS:2322 - Type '{ routingTest: Route; }' is not assignable to type 'Route'. Object literal may only specify known properties, and 'routingTest' does not exist in type 'Route'."

Now I’m a bit perplexed because I've tried "any", "route" and component types for my variable but all throw this error (surprised by any). I'm trying to detect when we are in mobile width range so I can change the route appropriately to a different component, giving me the ability to have completely different UI's for desktop and mobile.

Here is my code, I get the error on "{ path: '**', component: {{ routingTest }} }" line when declareing the "{{ routingTest }}" Var in the component route


const width  = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
console.log("this is the width (responsive),", width)
var routingTest: Any;
    
    if (width > 764)
    {
      routingTest = Testpage1Component
    }
    else
    { 
      routingTest = Testpage2Component
    }
console.log("routing file test", width , routingTest)

const routes: Routes = [
  { path: 'home', redirectTo: '' },
  { path: 'test1', component: Testpage2Component},
  { path: 'test', component: Testpage3Component},

  { path: '**', component: {{ routingTest }} }
];



@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})



export class AppRoutingModule {}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda