How to use router.navigateByUrl and router.navigate in Angular

后端 未结 4 557
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 04:04

https://angular.io/api/router/RouterLink gives a good overview of how to create links that will take the user to a different route in Angular4, however I can\'t find how to

4条回答
  •  感情败类
    2020-12-08 04:36

    From my understanding, router.navigate is used to navigate relatively to current path. For eg : If our current path is abc.com/user, we want to navigate to the url : abc.com/user/10 for this scenario we can use router.navigate .


    router.navigateByUrl() is used for absolute path navigation.

    ie,

    If we need to navigate to entirely different route in that case we can use router.navigateByUrl

    For example if we need to navigate from abc.com/user to abc.com/assets, in this case we can use router.navigateByUrl()


    Syntax :

    router.navigateByUrl(' ---- String ----');

    router.navigate([], {relativeTo: route})

提交回复
热议问题