{"id":7350,"date":"2019-09-28T18:59:54","date_gmt":"2019-09-28T13:29:54","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7350"},"modified":"2019-10-04T11:23:58","modified_gmt":"2019-10-04T05:53:58","slug":"magento-2-get-url-in-js-file","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-url-in-js-file\/","title":{"rendered":"Magento 2 &#8211; How to Get URL in JS File"},"content":{"rendered":"<p>In this post I am going to explain how to get URL in js file in magento 2.<\/p>\n<p>Use below code snippet to get URL in the js file.<\/p>\n<pre class=\"lang:default decode:true \">define([\r\n\t'jquery',\r\n\t'mage\/url'\r\n], function($, url) {\r\n\t\r\n\t\/\/ Login Page URL\r\n\tvar loginUrl = url.build('customer\/account\/login');\r\n\tconsole.log(loginUrl);\r\n\t\r\n\t\/\/ Customer Account URL\r\n\tvar accountUrl = url.build('customer\/account');\r\n\tconsole.log(accountUrl);\r\n});<\/pre>\n<p>Thats it. Enjoy Magento 2!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to get URL in js file in magento 2. Use below code snippet to get URL in the js file. define([ &#8216;jquery&#8217;, &#8216;mage\/url&#8217; ], function($, url) { \/\/ Login Page URL var loginUrl = url.build(&#8216;customer\/account\/login&#8217;); console.log(loginUrl); \/\/ Customer Account URL var accountUrl = url.build(&#8216;customer\/account&#8217;); console.log(accountUrl); });&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-url-in-js-file\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7378,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[10,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7350"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7350"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7350\/revisions"}],"predecessor-version":[{"id":7351,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7350\/revisions\/7351"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7378"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}