vue-router路由模式有多少种?

70 阅读1分钟

vvue-router有三种路由模式。

hash、history模式、abstract模式。

对应的源码如下

switch (mode) {
  case 'history':
	this.history = new HTML5History(this, options.base)
	break
  case 'hash':
	this.history = new HashHistory(this, options.base, this.fallback)
	break
  case 'abstract':
	this.history = new AbstractHistory(this, options.base)
	break
  default:
	if (process.env.NODE_ENV !== 'production') {
	  assert(false, `invalid mode: ${mode}`)
	}
}

其中三种模式的说明如下

1.hash模式

使用url的hash值来作路由。支持所有浏览器,包括了不支持HTML5 history API的浏览器。

2.history模式

依赖HTML5 history API和服务器配置。具体可以看HTML5 history模式。

3.abstract

支持所有JavaScript运行环境,如node.js服务器端