3

I'm trying to route a link to a page in my Angular application, but always receive the same error.

My Route.ts file has these routes:

export const ROUTES : Routes = [

    {path:'',component:AvisosComponent    },
    {path:'gerenciarModeloAviso', component:GerenciaModAvisoComponent },
    {path:'editModeloAviso/:id/:action', component: EditModeloAvisoComponent  }   

]

The problem is in the last route, that has two parameters.

And in the html I tried this:

<img src="../assets/editarOn.png" alt="Editar" [routerLink]="['/editModeloAviso',estrut.idAvisoEstrutura,'VIEW']" />

Then, I tried this:

<img src="../assets/editarOn.png" alt="Editar" [routerLink]="['/editModeloAviso',{id:estrut.idAvisoEstrutura,action:'VIEW'}]" />

And the error are always the same:

Error route

Just for comment, I changed the route file to this:

export const ROUTES : Routes = [

    {path:'',component:AvisosComponent    },
    {path:'gerenciarModeloAviso', component:GerenciaModAvisoComponent },
    {path:'editModeloAviso/:id/action', component: EditModeloAvisoComponent  }   

]

( I removed the ":" before the "action" word. Anyway, the error persists. )

If I use just one parameter in the route, It's ok, i have no error. But with two, no way.

Could You help me ?

Thanks in advance.

7
  • 1
    Can't reproduce: stackblitz.com/edit/…. Post a complete minimal example reproducing the problem, as I just did. Commented Mar 13, 2018 at 20:08
  • What part of the app you u need in this case? THe destiny page.ts ? Just looking to the code that I posted, do you see anything wrong ? Commented Mar 13, 2018 at 20:11
  • 1
    I don't need a part of the app. I need a complete minimal example, as I just posted, but which actually reproduces the problem. Commented Mar 13, 2018 at 20:14
  • what is your angular version 2 or 4? Commented Mar 13, 2018 at 20:25
  • I didn't know the stackBlitz. I edited the code, including more content. angular-router-basic-example-khfegh.stackblitz.io Commented Mar 13, 2018 at 20:36

1 Answer 1

6

The problem seems to be that you accidentally avoided to use an absolut path in your route.ts. Try this routes

export const ROUTES : Routes = [

    {path:'',component:AvisosComponent    },
    {path:'gerenciarModeloAviso', component:GerenciaModAvisoComponent },
    {path:'/editModeloAviso/:id/:action', component: EditModeloAvisoComponent  }   

]

in combination with this HTML-Part

<img src="../assets/editarOn.png" alt="Editar" [routerLink]="['/editModeloAviso',estrut.idAvisoEstrutura,'VIEW']" />

that should do.

Sign up to request clarification or add additional context in comments.

3 Comments

Tried, but give this error in browser console: Error: Invalid configuration of route '/editModeloAviso/:id/:action': path cannot start with a slash
Sorry, my bad. You're right. This construction is not supposed to work. I mixed something up.
DiabolicWords, I changed the path, removing the bar and the implementation finally works! The correct path is: {path:'editModeloAviso/:id/:action', component: EditModeloAvisoComponent } Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.