|
1 | 1 | # Route Options
|
| 2 | + |
| 3 | +There are a number of options you can use to customize the router behavior when creating a router instance. |
| 4 | + |
| 5 | +#### hashbang |
| 6 | + |
| 7 | +- default: true |
| 8 | +- only used in hash mode |
| 9 | + |
| 10 | + When the hashbang option is true, all hash paths will be formated to start with `#!`. For example `router.go('/foo/bar')` will set the browser URL to `example.com/#!/foo/bar`. |
| 11 | + |
| 12 | +#### history |
| 13 | + |
| 14 | +- default: false |
| 15 | + |
| 16 | + Enables HTML5 history mode. Leverages `history.pushState()` and `history.replaceState()` for history management. |
| 17 | + |
| 18 | + **Note**: when using the history mode, the server needs to be [properly configured](http://readystate4.com/2012/05/17/nginx-and-apache-rewrite-to-support-html5-pushstate/) so that a user directly visiting a deep link on your site doesn't get a 404. |
| 19 | + |
| 20 | +#### abstract |
| 21 | + |
| 22 | +- default: false |
| 23 | + |
| 24 | + Use an abstract history backend that doesn't rely on the browser. The abstract mode is useful in testing or in environments where actual URLs doesn't matter, for example in Electron or Cordova apps. The router will also fallback into abstract mode if loaded in a non-browser environment. |
| 25 | + |
| 26 | +#### root |
| 27 | + |
| 28 | +- default: null |
| 29 | +- only used in HTML5 history mode |
| 30 | + |
| 31 | + Define a root path for all router navigations. All paths used in route configurations, `router.go()`, `v-link` and exposed on route objects will be resolved relative to this root path, and the root path will always be included in the actual browser URL. |
| 32 | + |
| 33 | + For example, with `root: '/foo'`, `v-link="/bar"` will set the browser URL to `/foo/bar`. Directly visiting `/foo/bar` will match against `/bar` in your route config. |
| 34 | + |
| 35 | + In most cases, `root` is set-and-forget: you don't have to worry about it in your application code. |
| 36 | + |
| 37 | +#### linkActiveClass |
| 38 | + |
| 39 | +- default: `"v-link-active"` |
| 40 | + |
| 41 | + Configures the class to be applied to `v-link` elements when the current path matches its URL. The base class is applied as long as the current path starts with the `v-link` URL; when the current path matches the `v-link` URL exactly, an additional class with the `-exact` postfix will also be applied,the default being `v-link-active-exact`. So if you configure the class to be `my-custom-active`, the exact match class will be `my-custom-active-exact`. |
| 42 | + |
| 43 | +#### saveScrollPosition |
| 44 | + |
| 45 | +- default: false |
| 46 | +- only used in HTML5 history mode |
| 47 | + |
| 48 | + This option leverages the state associated with an HTML5 history `popstate` event to restore the scroll position when the user hits the back button. Note this might not work as expected if your `<router-view>` has transition effects. |
| 49 | + |
| 50 | +#### transitionOnLoad |
| 51 | + |
| 52 | +- default: false |
| 53 | + |
| 54 | + Whether to apply transition effect for `<router-view>`s on initial load. By default the components matched on initial load are rendered instantly. |
| 55 | + |
| 56 | +#### suppressTransitionError |
| 57 | + |
| 58 | +- default: false |
| 59 | + |
| 60 | + If set to `true`, uncaught errors inside transition hooks will be suppressed. |
0 commit comments