Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set window.location with TypeScript

People also ask

How do I use Windows location HREF in typescript?

href = 'https://google.com'; }); If you load the page and click on the button, you will navigate to the webpage you assigned to the property. The location. href property returns a string containing the whole URL and allows the href to be updated.

What is location in typescript?

The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the Document and Window interface have such a linked Location, accessible via Document.

What is window location assign?

The Location. assign() method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.

What is window location href?

Window Location Href The window.location.href property returns the URL of the current page.


window.location is of type Location while .attr('data-href') returns a string, so you have to assign it to window.location.href which is of string type too. For that replace your following line:

window.location = $link.attr('data-href');

for this one:

window.location.href = $link.attr('data-href');

you have missed the href:

Standard, To use window.location.href as window.location is technically an object containing:

Properties
hash 
host 
hostname
href    <--- you need this
pathname (relative to the host)
port 
protocol 
search 

try

 window.location.href = $link.attr('data-href');