Gagas17's avatar

Redirect To Route From Laravel View using JS

So i have a JS variable $decodedText and want to redirect to a page /newpage/$decodedText, i found window.location.href in JS but not succesfully done it with the $decodedText, code that failed below

window.location.href = '{{url("/newPage/$decodedText")}}'

0 likes
2 replies
folium's avatar
folium
Best Answer
Level 3

@gagas17 Try like this In your Laravel blade file.

<script>
  var decodedText = "{{ $decodedText }}";
  window.location.href = "/newPage/" + encodeURIComponent(decodedText);
</script>
1 like
Armani's avatar

Do it like this:

window.location.href = 'newPage/' + @json($decodedText)
1 like

Please or to participate in this conversation.