jsroute/javascriptroute

JavaScript路由

安装: 714

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 1

开放问题: 0

语言:JavaScript

v1.0 2022-08-31 08:18 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:34 UTC


README

第一步是使用composer安装包并自动更新你的composer.json文件,你可以通过运行以下命令来完成

composer require jsroute/javascriptroute 
composer dump-autoload

在JavaScript中使用route函数

routes/web.php 
<?php
Route::get("list",function(){
    return view("test");
})->name('list');
Route::get("detail/{id}",function(){
    return view("test");
})->name('detail');
Route::get("byid/{id}/{taxcd}",function(){
    return view("test");
})->>name('byid');
resources/views/test.blade.php
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Route JS</title>
    {!!javascriptroute()!!}
</head>
<body>
    <script>
        console.log(route("your name route"));
        //Route::get("list",function(){
        //    return view("test");
        //})->name('list');
        console.log(route("list")); // http://domain.com/list
        console.log(route("list",{
            category:1,
            type:"test"
        })); // http://domain.com/list?category=1&type=test
        ////////////////////////////////////////////////////////////////////////////////
        // Using a routing function that passes parameter
        // Route::get("detail/{id}",function(){
        //    return view("test");
        //})->name('detail');
        console.log(route("detail","abcdef"));// http://domain.com/detail/abcdef
        // parameter and queryString
        console.log(route("detail","abcdef",{
            name:"dev"
        }));// http://domain.com/detail/abcdef?name=dev
        ////////////////////////////////////////////////////////////////////////////////
        // Route::get("byid/{id}/{taxcd}",function(){
        //    return view("test");
        //})->>name('byid');
        console.log(route("byid",[1,"123456"])); //http://domain.com/byid/1/123456
         // parameter [] and queryString
        console.log(route("byid",[1,"123456"],{
            name:"dev"
        })); //http://domain.com/byid/1/123456?name=dev
    </script>
</body>
</html>