current position:Home>Vue router named routes, (nested) named views
Vue router named routes, (nested) named views
2022-04-29 18:25:06【Rookie_ Xiao Ka kumou】
Named route
stay Vue Router in except path outside , It can also provide... For any route name.
const routes = [
{
path: '/user/:username',
name: 'user',
component: User
}
]
To link to a named route , Can be directed to router-link
Component's to
Property to pass an object :
<router-link :to="{ name: 'user', params: { username: 'erina' }}">
User
</router-link>
It can also be used router.push()
:
router.push({
name: 'user', params: {
username: 'erina' } })
In both cases , The route will navigate to the path /user/erina
.
Named view
Sometimes I want to ( At the same level ) Show multiple views , Instead of nested presentation , For example, create a layout , Yes sidebar ( Side navigation ) and main ( Main content ) Two views , At this time, you can use the named view .
scene : There are multiple individually named views in the interface , Not just a single exit .
If router-view
No name set , Then the default is default.
<router-view class="view left-sidebar" name="LeftSidebar"></router-view>
<router-view class="view main-content"></router-view>
<router-view class="view right-sidebar" name="RightSidebar"></router-view>
One view rendered with one component , So for the same route , Multiple views require multiple components .
Be careful :component
To be changed to components
routes: [
{
path: '/',
components: {
default: Home,
// LeftSidebar: LeftSidebar Abbreviation
LeftSidebar,
// They are associated with `<router-view>` Upper `name` Attribute matching
RightSidebar,
},
},
],
const router = new Router({
mode: 'history',
routes,
})
Nested named views
The official sample
- Nav Just a regular component .
- UserSettings Is a view component .
- UserEmailsSubscriptions、UserProfile、UserProfilePreview Is a nested view component .
UserSettings Component's <template>
The part should be similar to the following code :
<!-- UserSettings.vue -->
<div>
<h1>User Settings</h1>
<NavBar />
<router-view />
<router-view name="helper" />
</div>
The above layout can be realized through this routing configuration :
{
path: '/settings',
// You can also configure named views on top-level routes
component: UserSettings,
children: [{
path: 'emails',
component: UserEmailsSubscriptions
}, {
path: 'profile',
components: {
default: UserProfile,
helper: UserProfilePreview
}
}]
}
copyright notice
author[Rookie_ Xiao Ka kumou],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204291825012063.html
The sidebar is recommended
- About node JS server related concepts
- Access control module (2)
- About virtual lists
- Developing figma plug-in using Vue 3 + vite
- Learn more about the garbage collection engine of chrome V8 JavaScript engine
- Vue3 uses vite instead of webpack
- How to upload applet code through node? Just take a look
- Using H5 video tag in Vue to play local video in pop-up window
- What is the difference between classes in Es5 and ES6?
- [Vue] play with the slot
guess what you like
[Part 4 of front-end deployment] using docker to build cache and multi-stage construction to optimize single page applications
Vue2 simple use of vant (based on Vue CLI)
node. JS server
React uses concurrent mode. When the rendering phase exceeds the time slice, high priority tasks jump the queue. How will the lanes on the fiber of the previous task be solved
Vuecli2 multi page, how to remove HTML suffix
Vue router dynamically modifies routing parameters
How to use webpack or configure quasar after context isolation is turned on by electron?
Vue3 how do parent components call child component methods
Es learning notes (I): http request
【Java WEB】AJAX
Random recommended
- Java project: nursing home management system (java + springboot + thymeleaf + HTML + JS + MySQL)
- Java project: drug management system (java + springboot + HTML + layui + bootstrap + seals + MySQL)
- Java project: agricultural material management system (java + springboot + easyUI + HTML + Maven + MySQL)
- How do Vue, native JS and jQuery feel about development
- The Ajax backend accepts post data and writes it directly to the database
- Java project: agricultural material management system (java + springboot + easyUI + HTML + Maven + MySQL)
- Brother Lao Yu takes you to play with esp32:14 and personally make a two-way wireless remote control (I)
- How to create JavaScript custom events
- A king's time, I learned nginx
- Vue quick start (with actual small items: Notepad, weather forecast, music player)
- Vue: convert user input to numeric type
- - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repom
- vue. config. Understanding of agent in JS
- After the node is successfully installed, CMD can be executed, but the compiler webstorm runs NPM install and prompts that there is no solution to this command
- How to develop and deploy front-end code in large companies
- Vue assigns permissions to buttons through instructions
- [development diary from 22 years to April] Vue problems encountered in actual projects and their solutions
- [methodology 1] CSS development skills - global style setting and local style
- vue3. 0 dynamically bind and obtain DOM through ref;
- How to use HTML to display segmentation
- How to use HTML for touch event in mobile terminal
- How to define and use HTML box model
- How to use the box pack attribute and box align attribute inside the box in HTML
- What are the differences and relationships among HTML, CSS and JS
- How to save home page as HTML
- How to solve the post request return 405 of nginx reverse proxy to HTML page
- How to upload pictures without refresh with HTML5 + PHP
- How to define HTML text tags, pictures, paths, hyperlinks and anchors
- How to upload static HTML files to the host or server
- How to use calculated and watch in Vue
- How does Vue Preview PDF, word, xls, PPT and txt files
- Can jQuery listen for events
- Luxury cars "senseless price increase", the configuration of the new Porsche Macan remains unchanged, with a maximum increase of 19000 yuan
- 1-ch579m program upgrade OTA (self built Internet of things platform) - ch579m uses its own Ethernet to remotely download and upgrade MCU program through HTTP (MCU program rotation check and update)
- The front-end downloads files, and the back-end sends gzip files. Is there a way to get the file size?
- Why does Vue route jump refresh the page?
- The conversion code of Babel in the project needs to include node_ Modules
- [nginx] prefix removal in nginx proxy pass configuration
- Vue packaging error module build failed: typeerror: this getOptions is not a function
- Use of I18N in Vue