-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(router-view): render children as placeholder
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
|
||
Vue.use(VueRouter) | ||
|
||
const Home = { template: '<div id="home">This is Home</div>' } | ||
const Header = { template: '<div id="header">This is Header</div>' } | ||
const Footer = { template: '<div id="footer">This is Footer</div>' } | ||
|
||
const router = new VueRouter({ | ||
mode: 'history', | ||
base: __dirname, | ||
routes: [ | ||
{ | ||
path: '/', | ||
components: { | ||
header: Header, | ||
default: Home, | ||
footer: Footer | ||
} | ||
} | ||
] | ||
}) | ||
|
||
router.beforeEach((to, from, next) => { | ||
setTimeout(() => { | ||
next() | ||
}, 1000) | ||
}) | ||
|
||
new Vue({ | ||
router, | ||
template: ` | ||
<div id="app"> | ||
<h1>router-view placeholder</h1> | ||
<router-view name="header"> | ||
<div id="header-loading">Loading header...</div> | ||
</router-view> | ||
<router-view> | ||
<div id="default-loading">Loading default...</div> | ||
</router-view> | ||
<router-view name="footer"></router-view> | ||
</div> | ||
` | ||
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
<div id="app"></div> | ||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/placeholder.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
'placeholder': function (browser) { | ||
browser | ||
.url('http://localhost:8080/placeholder/') | ||
.waitForElementVisible('#app', 1000) | ||
|
||
// Assert that 2 elements exist | ||
// because the last one doesn't have a placeholder | ||
.assert.count('#app div', 2) | ||
.assert.containsText('#header-loading', 'Loading header...') | ||
.assert.containsText('#default-loading', 'Loading default...') | ||
|
||
// When the timeout ends, assert if the components are there | ||
.waitForElementVisible('#home', 1000) | ||
.assert.count('.vue-router-placeholder', 0) | ||
.assert.containsText('#header', 'This is Header') | ||
.assert.containsText('#home', 'This is Home') | ||
.assert.containsText('#footer', 'This is Footer') | ||
|
||
.end() | ||
} | ||
} |