Is there a way to have href
without being redirect back to the root in angular2? As I have this <a href="" (click)="modal.open()"></a>
code to open up a modal but its redirecting me back to my home page.
I know its because of the routeConfig angular has, but is there a way to say bypass that?
{ path: '', component: LoginComponent, pathMatch: 'full'},
Note sure if removing href completely is valid, it may be without check w3c validation.
From the URL List, click the blue Hint Details button, which will bring up a slide-across window with specific details about the Hint for each URL. This will show you any outgoing anchor links with empty href attributes, highlighted in red in the HTML.
Indeed, you can leave it empty (W3 validator doesn't complain). Taking the idea one step further: leave out the ="". The advantage of this is that the link isn't treated as an anchor to the current page.
a target=”_blank” Open in New Browser Tab (or Window) The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.
You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.
I think a better answer to this question could be:
<a href="" (click)='$event.preventDefault();modal.open()'>
href="javascript:;"
will produce an error after clicking link when Content-Security-Policy
disallows inline scripts (script-src: 'self';
for example) (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src).
You can use empty href with event.preventDefault() on click instead.
<a href="" (click)="$event.preventDefault()">Link</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With