vue-router

Vue-router redirect on page not found (404)

被刻印的时光 ゝ 提交于 2019-11-27 20:01:33
I'm trying to redirect to 404.html on page not found using the router.beforeEach global hook, without much success (using Vue and Vue-Router 1.0): router.beforeEach(function (transition) { if (transition.to.path === '/*') { window.location.href = '/404.html' } else { transition.next() } }); This is not redirecting to page 404.html when a non-existing route is inserted, just giving me an empty fragment. Only when hard-coding some-site.com/* will it redirect to the expected some-site.com/404.html I'm sure there's something very obvious here that I'm overlooking, but I cannot figure out what.

Vue js rerender the same component when changing route

二次信任 提交于 2019-11-27 18:22:41
问题 I have one auth component that I am using both in the login and the signup route. const routes = [{ path : '/', name: 'home', component: Home }, { path : '/signin', name: 'signin', component: Auth }, { path : '/signup', name: 'signup', component: Auth }]; If for example, I'm on the login page The problem is if I type something in the text inputs and go to the signup the text is still there, how I force the component to reinitialize? 回答1: The better way to do this is actually to bind the

How to pass a value from Vue data to href?

喜夏-厌秋 提交于 2019-11-27 18:13:57
I'm trying to do something like this: <div v-for="r in rentals"> <a bind-href="'/job/'r.id"> {{ r.job_title }} </a> </div> I can't figure out how to add the value of r.id to the end of the href attribute so that I can make an API call. Any suggestions? asemahle You need to use v-bind: or its alias : . For example, <a v-bind:href="'/job/'+ r.id"> or <a :href="'/job/' + r.id"> Or you can do that with ES6 template literal: <a :href="`/job/${r.id}`" Waqar Shahid If you want to display links coming from your state or store in Vue 2.0, you can do like this: <a v-bind:href="''"> {{ url_link }} </a>

How to use vue-resource ($http) and vue-router ($route) in a vuex store?

耗尽温柔 提交于 2019-11-27 18:01:05
问题 Before I was getting movie detail from the component's script. The function first check whether the movie ID of the store is same as of the route's param movie ID. If its same then don't get the movie from the server API, or else get the movie from the server API. It was working fine. But now I am trying to get the movie details from the store's mutation. However I am getting error Uncaught TypeError: Cannot read property '$route' of undefined How to use vue-router ($route) to access the

Vue - Router 路由

你说的曾经没有我的故事 提交于 2019-11-27 16:17:08
路由的注册 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="x-ua-compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <title>Title</title> 8 <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> 9 <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> 10 </head> 11 <body> 12 <div id="app"> 13 <!--<router-link to="/">首页</router-link>--> 14 <!--<router-link to="/login">登录</router-link>--> 15 <router-link :to="{name: 'home'}">首页</router-link> 16 <router-link :to="{name:

Vue路由vue-router

蓝咒 提交于 2019-11-27 16:14:50
前面的话   在Web开发中,路由是指根据URL分配到对应的处理程序。对于大多数单页面应用,都推荐使用官方支持的vue-router。Vue-router通过管理URL,实现URL和组件的对应,以及通过URL进行组件之间的切换。本文将详细介绍Vue路由vue-router 安装   在使用vue-router之前,首先需要安装该插件 npm install vue-router   如果在一个模块化工程中使用它,必须要通过 Vue.use() 明确地安装路由功能 import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter)   如果使用全局的 script 标签,则无须如此 使用   用Vue.js + vue-router创建单页应用非常简单。使用Vue.js ,已经可以通过组合组件来组成应用程序,把vue-router添加进来,需要做的是,将组件(components)映射到路由(routes),然后告诉 vue-router 在哪里渲染它们   下面是一个实例 <div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 router-link 组件来导航,通过传入 `to` 属性指定链接,<router-link> 默认会被渲染成一个 `<a>` 标签

vue中的路由vue-router

一曲冷凌霜 提交于 2019-11-27 16:14:23
最近在重新学习vue整理一下自己学习的一些觉得重要的知识点 在实际项目中我们会遇到各种各样的页面跳转与嵌套就有了1.动态路由2.嵌套路由3.编程式路由4.命名路由 1.动态路由,什么是动态路由就是类似于:(运用场景一般就是商城的详情页面) 模式 匹配路由 $route.params /user/:username /user/evan {username:'evan'} /user/:username/post/:post_id /user/evan/post/123 {username:'evan',post_id:123} 传一个参数的时候在router/index.js中 import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' Vue.use(Router) export default new Router({ routes: [ { path: '/HelloWorld/:post_id', name: 'HelloWorld', component: HelloWorld } ] }) 在HelloWorld页面中 <template> <div class="hello"> 这是一个hello页面的内容 <!--

Element/vue router连续点击多次路由报错解决方法

馋奶兔 提交于 2019-11-27 16:12:49
Element-ui 点击多次路由会报错:NavigationDuplicated {_name: “NavigationDuplicated”, name: “NavigationDuplicated”} 查找到了一篇比较好用的解决文章 ( 亲测有效 ), 方法如下↓ 把项目依赖的 node_modules 文件夹删除, 然后再 npm install 重新下载依赖包就可以解决。 如果在重新下载依赖包时,安装的vue-router还是之前出错的那个版本,那么要怎么解决呢?解决方法也很简单,在项目目录下运行 npm i vue-router@3.0 -S 即可 如果不想换 vue-router 的版本 或者 还是 没有用,那么可以用以下方法 在main.js下添加一下代码: import Router from 'vue-router' const originalPush = Router . prototype . push Router . prototype . push = function push ( location ) { return originalPush . call ( this , location ) . catch ( err => err ) } 来源: https://blog.csdn.net/qq_40282732/article

Add event listener to <router-link> component using “v-on:” directive - VueJS

家住魔仙堡 提交于 2019-11-27 15:35:23
问题 I'm attempting to add a custom handler InlineButtonClickHandler to a <router-link> component's click event, so that I can emit a custom appSidebarInlineButtonClick event. But, my code isn't working. What am I doing wrong? <template> <router-link :to="to" @click="InlineButtonClickHandler"> {{ name }} </router-link> </template> <script type="text/babel"> export default { props: { to: { type: Object, required: true }, name: { type: String, required: true } }, methods: { InlineButtonClickHandler

vue router

别说谁变了你拦得住时间么 提交于 2019-11-27 14:04:41
二、vue-router是什么 这里的路由并不是指我们平时所说的硬件路由器, 这里的路由就是SPA(单页应用)的路径管理器 。再通俗的说,vue-router就是WebApp的链接路径管理系统。 vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用。vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来。传统的页面应用,是用一些超链接来实现页面切换和跳转的。在vue-router单页面应用中,则是路径之间的切换,也就是组件的切换。 路由模块的本质 就是建立起url和页面之间的映射关系 。 至于我们为啥不能用a标签,这是因为用Vue做的都是单页应用( 当你的项目准备打包时,运行 npm run build 时,就会生成dist文件夹,这里面只有静态资源和一个index.html页面 ),所以你写的<a></a>标签是不起作用的,你必须使用vue-router来进行管理。 三、vue-router实现原理 SPA(single page application):单一页面应用程序,只有一个完整的页面;它在加载页面时,不会加载整个页面,而是只更新某个指定的容器中内容。 单页面应用(SPA)的核心之一是: 更新视图而不重新请求页面 ;vue-router在实现单页面前端路由时,提供了两种方式