0

When navigating to a URL with a querystring like:

http://localhost:5000/search?q=test+test the url suddenly becomes http://localhost:5000/search?query=test%2Btest

Is it possible to alter this behaviour? I don't see anything wrong with the plus sign and I'd like to keep the sign in the url for various reasons.

raven
  • 2,303
  • 1
  • 18
  • 43
freakshow
  • 451
  • 8
  • 16

2 Answers2

0

As described in this answer, you can provide your own custom url serializer by implementing the UrlSerializer. The serializer should look something like this:

class CustomUrlSerializer implements UrlSerializer {
    parse(url: string): UrlTree {
        // Custom code here
    }

    serialize(tree: UrlTree): string {
        // Custom code here
    }
}

You then need to provide your own implementation instead of the UrlSerializer:

providers: [
    { provide: UrlSerializer, useClass: CustomUrlSerializer },
    ...
]
Fynn
  • 4,639
  • 3
  • 29
  • 62
-1

The plus sign is not a valid character in an url. But %2B is equivalent to + so at the reciving end it will be possible to parse it back to +

orsolli
  • 54
  • 6