Laravel 4-重定向到javascript代码Blade模板内的路由

Laravel 4- redirect to a route inside javascript code Blade template

本文关键字:路由 Blade 代码 重定向 javascript Laravel      更新时间:2023-09-26

我正在尝试使用javascript和刀片引擎编写一个简单的重定向,这是我想做的一个例子:

javascript代码:

<p>Click the button to go to the home page</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction()
{
    var x;
    var r=confirm("Are you sure you want to leave this page ?");
    if (r==true)
    {
      //Redirect to home
    }
    else
    {
     //stay here
    }
    document.getElementById("demo").innerHTML=x;
}
</script>

当我使用return Redirect::route('home')时,它不起作用,正确的语法是什么,很抱歉我的英语不好。

$url=url::to('fo');//任何其他路由名称,如home,或使用URL::route()

<script>
function myFunction()
{
   var x;
   var r=confirm("Are you sure you want to leave this page ?");
   if (r)
   {
      window.location="{{URL::to('home')}}";
   }
...

更多信息:http://laravel.com/docs/routing