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,381
  • 2
  • 20
  • 44
freakshow
  • 461
  • 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,753
  • 3
  • 32
  • 69
-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
  • 7