GVKun编程网logo

Vue 路由器 url 更改但内容不变(vue修改路由)

1

在本文中,我们将给您介绍关于Vue路由器url更改但内容不变的详细内容,并且为您解答vue修改路由的相关问题,此外,我们还将为您提供关于$str=asdfasdf123541[url]asdfasdf

在本文中,我们将给您介绍关于Vue 路由器 url 更改但内容不变的详细内容,并且为您解答vue修改路由的相关问题,此外,我们还将为您提供关于$str =asdfasdf123541[url]asdfasdf[/url]cxgew435asdfasdf; [url]asdfasdf[/url] 想把这块去掉,最好的方法是什么。、Laravel-vuejs(Vue 路由器)Javascript 在 onchange url、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、Passport.js 与 Vue 路由器 - 导航卫士的知识。

本文目录一览:

Vue 路由器 url 更改但内容不变(vue修改路由)

Vue 路由器 url 更改但内容不变(vue修改路由)

如何解决Vue 路由器 url 更改但内容不变

当我访问 http://127.0.0.1:8080 时,在浏览器 url 中显示 http://127.0.0.1:8080/#/topicManagement/topicManagement 当我点击 div(必须为“/topicManagement/appConfigTopic”)时,它会路由到浏览器 url 中的 http://127.0.0.1:8080/#/topicManagement/appConfigTopic,但页面内容没有改变。

我已阅读此 Click on link changes the url but not the content/data on page,它具有相同的路由器。虽然我的路由器不同。

路由器配置:

routes: [
    {
        path: ''/'',redirect:''index'',},{
        path: ''/index'',name: ''index'',component: index,redirect:''/topicManagement'',children:[
            {
                path:''/topicManagement'',name:''topic'',component:topicManagement,//redirect:''/topicManagement/topicManagement'',children:[
                    {
                        path:''/topicManagement/topicManagement'',name:''topicManagement'',componment:topicManagement
                    },{
                        path:''/topicManagement/appConfigTopic'',name:''appConfigTopic'',componment:appConfigTopic
                    },{
                        path:''/topicManagement/courseInteractTopic'',name:''courseInteractTopic'',componment:courseInteractTopic
                    }
                ]
            }
    }
]

模板

主题管理

<template>
    <div>
        <div>
            <div>
                <span>主题管理</span>
            </div>
            <div>
                <router-link to="/topicManagement/appConfigTopic">
                    <span>+</span>
                    <span>添加APP配置主题</span>
                </router-link>
                <router-link to="/topicManagement/courseInteractTopic">
                    <span>+</span>
                    <span>添加课中互动主题</span>
                </router-link>
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>

编辑

当我切换到下面的路由器时,它显示 http://127.0.0.1:8080/#/topicManagement 的空白页面

    routes: [
        {
            path: ''/'',{
            path: ''/index'',children:[
                {
                    path:''topicManagement'',//redirect:''topicManagement'',children:[
                        /*
                        {
                            path:''/topicManagement/topicManagement'',componment:topicManagement
                        },*/
                        {
                            path:''appConfigTopic'',name:''topicManagementAppConfigTopic'',componment:appConfigTopic
                        },{
                            path:''courseInteractTopic'',name:''topicManagementCourseInteractTopic'',componment:courseInteractTopic
                        }
                    ]
                }

解决方法

您应该删除子路由路径中的前置斜线 / :

...
    {
        path: ''/index'',name: ''index'',component: index,redirect:''/topicManagement'',children:[
            {
                path:''topicManagement'',// not path:''/topicManagement''
                name:''topic'',....

$str =asdfasdf123541[url]asdfasdf[/url]cxgew435asdfasdf; [url]asdfasdf[/url] 想把这块去掉,最好的方法是什么。

$str =asdfasdf123541[url]asdfasdf[/url]cxgew435asdfasdf; [url]asdfasdf[/url] 想把这块去掉,最好的方法是什么。

 $str =asdfasdf123541[url]asdfasdf[/url]cxgew435asdfasdf;

[url]asdfasdf[/url]  想把这块去掉,最好的方法是什么。

Laravel-vuejs(Vue 路由器)Javascript 在 onchange url

Laravel-vuejs(Vue 路由器)Javascript 在 onchange url

嗯,我明白你想要什么。您想在所有组件中调用 JavaScript 文件。例如,JavaScript 插件(如 select2、datapicker 等)的 init.js 必须在所有组件中调用,我没听错吗?

无论如何

#1 在路径 external.js 中创建文件 resources/js/

external.js

function add_script(src) {
    if(document.querySelector("script[src='" + src + "']")){ return; }
    let script = document.createElement('script');
    script.setAttribute('src',src);
    script.setAttribute('type','text/javascript');
    document.body.appendChild(script)
}

function rem_script(src) {
    let el = document.querySelector("script[src='" + src + "']");
    if(el){ el.remove(); }
}

在您的 app.js 中添加

import {add_script,rem_script} from './external';

router.beforeEach((to,from,next) => {


  /* It would be nice to add a pre-loader here d
     so that the page design is not affecte
  */
  // Track your console :)
  console.log('Hi before load');
   
  // Add your script
  add_script('path/to/your_js');
  next()
})
router.afterEach(() => {
  // Here you can remove loader after loaded


  // Track your console :)
  console.log('Hi After load');


  // remove_included_js file but still working :)
  rem_script('path/to/your_js');    

})

现在应该在每个组件中调用这个文件 path/to/your_js

完成,就是这样:)

但我从来没有在大型项目中这样建议你 :) 但正如@equi 和@Stefano A. 所说,他们是对的。

,

router-link 允许在启用路由器的 JS 应用程序中进行 Vue.js 导航。这允许通过减少加载新页面所需的时间来优化用户体验。具体来说,新页面是异步注入DOM的。

为了实现您想要的结果,我们可以将我们希望在页面加载时运行的功能放在组件的 mounted() 方法中:

//component Test
<template>
    <div>
      <span> Test Page </span>
    </div>
</template>
<script>
export default 
{
   data() {
      return { }
   },mounted() {
      alert('Page loaded!'); // JS functionality to be run on component mount
   }
}
</script>

如果需要,我们可以在 .js 方法中加载外部 mounted() 文件:

mounted() {
    let newScript = document.createElement('script')
    newScript.setAttribute('src','https://<URL>/script.js')
    document.head.appendChild(newScript)
}
,

我没有看到它坏了。如果您考虑缺少警报消息:您可能将它作为 created() 或mounted() 生命周期钩子的一部分放在 App.vue 组件中。它只显示一次,因为 App.vue 组件保持加载状态,并且您正在使用路由器在 Test.vue 和 Home.vue 之间切换。 App.vue 在刷新之前不会经历其生命周期挂钩。

但是,如果您想在每次路由更改时执行部分代码,则应该在 vue 路由器上使用导航守卫。

NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序

NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序

HttpClient 导入您的 .service.ts

import { HttpClient } from '@angular/common/http';

HttpClientModule导入app.module.ts并添加HttpClientModule导入数组

import { HttpClientModule } from '@angular/common/http';

 imports: [
    BrowserModule,AppRoutingModule,HttpClientModule
  ],
,

我在使用 @angular/router 的服务中遇到了同样的错误。我能够通过替换来修复它

@Injectable()

@Injectable({
  providedIn: 'root'
})

在服务类中。

Passport.js 与 Vue 路由器 - 导航卫士

Passport.js 与 Vue 路由器 - 导航卫士

如何解决Passport.js 与 Vue 路由器 - 导航卫士

我使用 Vue Router 进行导航,使用passport.js 来登录/注册我的应用程序。登录/注册系统工作正常,并使用 mongodb 数据库进行设置。

但是,我无法让我的路线保护与护照功能一起使用以确保身份验证。

这是我目前的代码:

const { ensureAuthenticated } = require(''../../Configurators/userAuthentication'');

const routes = [
{path: ''/afterLogin'',name: ''AfterLogin'',component: () => import(''../views/afterLogin.vue''),beforeEnter : ensureAuthenticated},]

这是我的身份验证功能:

module.exports = {
    ensureAuthenticated: function(req,res,next) {
        if (req.isAuthenticated()) {
            return next();
        }
        req.flash(''error_msg'',''Please log in to view that resource'');
        res.redirect(''/users/login'');
    }
};

我对 Vue Router 非常陌生,因此非常感谢您的帮助。

今天的关于Vue 路由器 url 更改但内容不变vue修改路由的分享已经结束,谢谢您的关注,如果想了解更多关于$str =asdfasdf123541[url]asdfasdf[/url]cxgew435asdfasdf; [url]asdfasdf[/url] 想把这块去掉,最好的方法是什么。、Laravel-vuejs(Vue 路由器)Javascript 在 onchange url、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、Passport.js 与 Vue 路由器 - 导航卫士的相关知识,请在本站进行查询。

本文标签: