【问题标题】:Laravel/Vue - Get list of routes from backendLaravel/Vue - 从后端获取路由列表
【发布时间】:2021-05-05 09:02:50
【问题描述】:

我在resources/js/router.js 中有这个路由器代码

import Vue from 'vue';
import VueRouter from 'vue-router';

import ClientFeature1 from './components/ClientFeature1';
import ClientFeature2 from './components/ClientFeature2';
import InternalFeature1 from './components/InternalFeature1';
import InternalFeature2 from './components/InternalFeature2';

Vue.use(VueRouter);

export default new VueRouter({
    routes : [
        { path : '/client-1', component : ClientFeature1, name : "Client Feature 1" },
        { path : '/client-2', component : ClientFeature2, name : "Client Feature 2" },
        { path : '/internal-1', component : InternalFeature1, name : "Internal Feature 1" },
        { path : '/internal-2', component : InternalFeature2, name : "Internal Feature 2" }
    ],
    mode: 'hash'
});

这很好用,但正如您所见,我正在为客户端和仅供内部使用的路由加载所有路由。

如何仅在用户客户端或内部使用时加载?任何建议表示赞赏。

提前致谢。

【问题讨论】:

  • 你想要什么?单页应用?还想使用web.php 吗?
  • @KamleshPaul 单页应用程序。但可以被不同的用户使用
  • 您可以根据自己的需求使用的路由器。
  • @KamleshPaul 我想我明白你的意思。但是如果前端或用户能够看到这种情况,那会安全吗?
  • @Ohgodwhy 这实际上是一个非常好的观点。谢谢大家。

标签: javascript php laravel vue.js vue-router


【解决方案1】:

export default new VueRouter({
    routes : [
        {
          path : '/client-1',
          name : "Client Feature 1" 
          // component : ClientFeature1, //asis
          component: () => import(/* webpackChunkName: 'ClientFeature1' */'./components/ClientFeature1')
         },
         // ...
    ],
    mode: 'hash'
});

【讨论】:

    猜你喜欢
    • 2019-08-11
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 2018-11-30
    • 2018-03-27
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多