Custom encoding for urls using Angular 2 Router (using a + sign in place of a space)

后端 未结 3 2239
臣服心动
臣服心动 2020-12-09 12:39

I am using an Angular 2 Router to update the query params in a URL for a search application. I am attempting to replace spaces in a query with + signs. However, + signs are

3条回答
  •  长情又很酷
    2020-12-09 13:11

    I ran into an issue specifying the custom provider. There was apparently a circular dependency when compiling with the --prod flag causing an error with the text: useClass cannot by null. This is how I worked around that error:

    In AppModule, define the following:

    const customUrlSerializer = new CustomUrlSerializer();
    const CustomUrlSerializerProvider = {
        provide: UrlSerializer,
        useValue: customUrlSerializer
    };
    

    Then in the providers array, add the provider you specified above.

    ...
    providers: [CustomUrlSerializerProvider]
    ...
    

提交回复
热议问题