const args = process.argv.slice(2)
// if we are running yarn dev locally, we can pass --dev to avoid launching another server instance
-const server =
- args.indexOf('--dev') > -1 ? null : require('../../examples/server')
+const server = args.indexOf('--dev') > -1 ? null : require('../examples/server')
// allow running browserstack local
const isLocal = args.indexOf('--local') > -1
+++ /dev/null
-const bsStatus = require('../browserstack-send-status')
-
-module.exports = {
- ...bsStatus(),
-
- '@tags': ['history'],
-
- basic(browser) {
- browser
- .url('http://localhost:8080')
- .waitForElementVisible('#app', 1000)
- // .assert.count('li', 8)
-
- .click('li:nth-child(2) a')
- .assert.urlEquals('http://localhost:8080/documents/%E2%82%ACuro')
- .assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
- .assert.containsText('#path', '/documents/%E2%82%ACuro')
- .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
-
- // check initial visit
- .url('http://localhost:8080/users/2')
- .waitForElementVisible('#app', 1000)
- .assert.containsText('#params', JSON.stringify({ id: '2' }, null, 2))
-
- .end()
- },
-}
--- /dev/null
+const bsStatus = require('../browserstack-send-status')
+
+const baseURL = 'http://localhost:8080/encoding'
+
+module.exports = {
+ ...bsStatus(),
+
+ '@tags': ['history', 'encoding'],
+
+ /** @type {import('nightwatch').NightwatchTest} */
+ basic(browser) {
+ browser
+ .url(baseURL)
+ .waitForElementVisible('#app', 1000)
+
+ .click('li:nth-child(3) a')
+ .assert.urlEquals(baseURL + '/documents/%E2%82%ACuro')
+ .assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
+ .assert.containsText('#path', '/documents/%E2%82%ACuro')
+ .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
+
+ // check initial visit
+ .url(baseURL + '/encoding/documents/%E2%82%ACuro')
+ .waitForElementVisible('#app', 1000)
+ .assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
+ .assert.containsText('#path', '/documents/%E2%82%ACuro')
+ // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
+ // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
+
+ browser
+ .getText('#params', function(res) {
+ this.assert.equal(res.value, JSON.stringify({ id: '€uro' }, null, 2))
+ console.log(res.state)
+ })
+ .end()
+ },
+}
<div id="app">
<section class="info">
Name:
- <pre id="name">{{ $route.name }}</pre>
+ <pre id="name">{{ route.name }}</pre>
</section>
<section class="info">
Params:
- <pre id="params">{{ $route.params }}</pre>
+ <pre id="params">{{ route.params }}</pre>
</section>
<section class="info">
Query:
- <pre id="query">{{ $route.query }}</pre>
+ <pre id="query">{{ route.query }}</pre>
</section>
<section class="info">
Hash:
- <pre id="hash">{{ $route.hash }}</pre>
+ <pre id="hash">{{ route.hash }}</pre>
</section>
<section class="info">
FullPath:
- <pre id="fullPath">{{ $route.fullPath }}</pre>
+ <pre id="fullPath">{{ route.fullPath }}</pre>
</section>
<section class="info">
path:
- <pre id="path">{{ $route.path }}</pre>
+ <pre id="path">{{ route.path }}</pre>
</section>
<hr />
>
</li>
<li>
- <a href="/encoding/n/%E2%82%AC">/n/%E2%82%AC (force reload)</a>
+ <a href="/encoding/documents/%E2%82%AC"
+ >/n/%E2%82%AC (force reload)</a
+ >
</li>
<li>
- <a href="/encoding/n/€">/n/€ (force reload): not valid tho</a>
+ <a href="/encoding/documents/€"
+ >/n/€ (force reload. not valid but should not crash the router)</a
+ >
</li>
</ul>
-import { Router, plugin, createHistory } from '../../src'
+import { createRouter, createWebHistory, useRoute } from '../../src'
import { RouteComponent } from '../../src/types'
-import Vue from 'vue'
+import { createApp } from 'vue'
const component: RouteComponent = {
template: `<div>A component</div>`,
}
const Document: RouteComponent = {
- template: `<div>Document: {{ $route.params.id }}</div>`,
+ template: `<div>Document: {{ route.params.id }}</div>`,
+ setup() {
+ return { route: useRoute() }
+ },
}
-const router = new Router({
- history: createHistory('/' + __dirname),
+const router = createRouter({
+ history: createWebHistory('/' + __dirname),
routes: [
{ path: '/', component: Home, name: 'home' },
{ path: '/documents/:id', name: 'docs', component: Document },
],
})
-// use the router
-Vue.use(plugin)
-
-// @ts-ignore
-window.vm = new Vue({
- el: '#app',
- // @ts-ignore
- router,
+const app = createApp({
+ setup() {
+ const route = useRoute()
+ return { route }
+ },
})
+app.use(router)
+
+window.vm = app.mount('#app')
a:hover {
color: #4fc08d;
}
+
+.router-link-active {
+ color: darkorange;
+}
+.router-link-exact-active {
+ color: red;
+}
-import { Router, plugin, createHashHistory } from '../../src'
+import { createRouter, createWebHistory } from '../../src'
import { RouteComponent } from '../../src/types'
-import Vue from 'vue'
+import { createApp } from 'vue'
const component: RouteComponent = {
template: `<div>A component</div>`,
template: `<div>Document: {{ $route.params.id }}</div>`,
}
-const router = new Router({
- history: createHashHistory('/' + __dirname),
+const router = createRouter({
+ history: createWebHistory('/' + __dirname),
routes: [
{ path: '/', component: Home, name: 'home' },
{ path: '/documents/:id', name: 'docs', component: Document },
],
})
-// use the router
-Vue.use(plugin)
+const app = createApp({})
+app.use(router)
-// @ts-ignore
-window.vm = new Vue({
- el: '#app',
- // @ts-ignore
- router,
-})
+window.vm = app.mount('#app')
<ul>
<li v-for="example in examples">
- <a :href="example">/{{ example }}</a>
+ <a :href="'/' + example">/{{ example }}</a>
</li>
</ul>
</div>
-import Vue from 'vue'
+import { createApp, ComponentPublicInstance } from 'vue'
const context = require.context('.', true, /^.{2,}\/index\.ts$/)
const DIR_RE = /^\.\/([^/]+)\//
})
examples.sort()
-new Vue({
- el: '#app',
- data: { examples },
+declare global {
+ interface Window {
+ app: typeof app
+ vm: ComponentPublicInstance
+ }
+}
+
+const app = createApp({
+ data: () => ({ examples }),
})
+
+app.mount('#app')
+window.app = app
--- /dev/null
+const webpack = require('webpack')
+const WebpackDevServer = require('webpack-dev-server')
+const webpackConfig = require('./webpack.config')
+
+const compiler = webpack(webpackConfig)
+
+const app = new WebpackDevServer(compiler, webpackConfig.devServer)
+
+const port = process.env.PORT || 8080
+module.exports = app.listen(port, () => {
+ console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
+})
{
- "include": ["index.ts", "*/*ts"],
+ "include": ["index.ts", "*/*ts", "../src/global.d.ts"],
"compilerOptions": {
"target": "es5",
"module": "commonjs",
})),
},
hot: true,
+ stats: 'minimal',
},
entry: examples.reduce(
extensions: ['.ts', '.tsx', '.js'],
},
plugins: [
+ new webpack.DefinePlugin({
+ __DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
+ __BROWSER__: `typeof window !== 'undefined'`,
+ 'process.env': {
+ NODE_ENV: JSON.stringify(process.env.NODE_ENV),
+ },
+ }),
...examples.map(
name =>
new HtmlWebpackPlugin({
chunks: ['index'],
template: resolve(__dirname, 'index.html'),
}),
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(process.env.NODE_ENV),
- },
- }),
],
}