Query parameters
https://something.com/user/456?locale=en
1 | <router-link |
Adding hash fragment
1 | <router-link :to="{ name: pathName, hash: '#text' }"> |
Scroll behavior
1 | import { routes } from './routes.js' |
Here, routes are all our routes kept in a separate file. The scrollBehavior()
function is what manages the scrolling of our routes. It has 3 parameters:
- to — This represents the new route we will be visiting
- from — This is the previous route we came from. So if we click on a
<router-link>
on Home page to visit the About page, then to would be our About page and from is the Home page. - savedPosition — This is the important parameter. It represents the previous position before scrolling. It will become clear after I explain what the above function does.
参考:
https://medium.com/@NAPOLEON039/the-lesser-known-amazing-things-vuerouter-can-do-3fbb2c191c00