I need to modify the url on copy from an angular project.
When the user selects URL and copy (like ctrl+c), it is
page/item/123
I need to modify that to
page/item?id=123
How can I do that?
Reason: I could not make the web.config work to pass the full path (item/123), so angular cannot parse what is not there.
However, I can make item?id=.... work, so it opens "item" and there I can get the query parameter.
Added: in the comments it was suggested to do it one way/the right way only and I agree - but I am here because my original problem cannot be solved: web.config - forward full path with parameter
How to make rules work with parameters and pass the full path for parsing
Here's how it can be done:
html
<div (copy)="handleCopy($event)">page/item/1234</div>
ts
handleCopy(event: ClipboardEvent) {
event.clipboardData.setData('text/plain',
document.getSelection().toString().replace(/\/(?=[^\/]*$)/, "?id="));
event.preventDefault();
}