Passing params angular 2 traditional way

后端 未结 1 1061
野的像风
野的像风 2021-01-28 05:36

I am trying to pass parameters to one component in this format www.domain.com?param=value, but Angular keep sending parameters like this www.domain.com;param=

相关标签:
1条回答
  • 2021-01-28 06:00

    Angular provides three types of parameters:

    • Required parameters
    • Optional parameters
    • Query parameters

    The look of the URL and the syntax for navigating using the parameters is different depending on which type of parameter you want to use.

    If you want to use the "?" style, then you want the query parameters.

    Query Parameters:

    • Are NOT included in the route path configuration. So if you want query parameters, do NOT add the :id to the path.

    NOT this:

    {path: 'shop/new/:id', component: NewShopComponent, canActivate: [AuthManager]},
    

    RATHER this:

    {path: 'shop/new', component: NewShopComponent, canActivate: [AuthManager]},
    

    Then you navigate to the route like this:

    this.router.navigate(['/shops'], 
       { 
        queryParams: { id: id }
       }
    );
    

    If you want more information on how to use routing ... check this out: https://app.pluralsight.com/library/courses/angular-routing/table-of-contents

    0 讨论(0)
提交回复
热议问题