<hr />
<div id="app">
- <section class="info">
- Name:
- <pre id="name">{{ route.name }}</pre>
- </section>
-
- <section class="info">
- Params:
- <pre id="params">{{ route.params }}</pre>
- </section>
-
- <section class="info">
- Query:
- <pre id="query">{{ route.query }}</pre>
- </section>
-
- <section class="info">
- Hash:
- <pre id="hash">{{ route.hash }}</pre>
- </section>
-
- <section class="info">
- FullPath:
- <pre id="fullPath">{{ route.fullPath }}</pre>
- </section>
-
- <section class="info">
- path:
- <pre id="path">{{ route.path }}</pre>
- </section>
-
- <hr />
-
<ul>
+ <li><router-link to="/">/</router-link></li>
+ <li><router-link to="/foo">/foo</router-link></li>
+ <li><router-link to="/bar">/bar</router-link></li>
+ <li><router-link :to="{ name: 'encoded' }">/n/é</router-link></li>
+ <li><router-link to="/unicode/é">/unicode/é</router-link></li>
<li>
- <router-link to="/">/</router-link>
- </li>
- <li>
- <router-link to="/documents/%E2%82%AC"
- >/documents/%E2%82%AC</router-link
- >
- </li>
- <li>
- <router-link :to="{ name: 'docs', params: { id: '€uro' }}"
- >/documents/€uro (object)</router-link
+ <router-link :to="{ name: 'unicode', params: { id: 'é' }}"
+ >/unicode/é (correctly encoded)</router-link
>
</li>
<li>
- <router-link
- :to="{ name: 'home', query: { currency: '€uro', 'é': 'e' }}"
+ <router-link :to="{ path: '/', query: { t: 'é', 'é': 'e' }}"
>/?currency=€uro&é=e (object)</router-link
>
</li>
<li>
- <a href="/hash/#/documents/%E2%82%AC"
- >/documents/%E2%82%AC (force reload)</a
+ <a href="/hash/#/unicode/%E2%82%AC"
+ >/unicode/%E2%82%AC (force reload)</a
>
</li>
<li>
- <a href="/hash/#/documents/€"
- >/documents/€ (force reload): not valid tho</a
+ <a href="/hash/#/unicode/€"
+ >/unicode/€ (force reload. not valid but should not crash the
+ router)</a
>
</li>
</ul>
+ <p>
+ path: <code id="path">{{ route.path }}</code>
+ <br />
+ query.t: <code id="query-t">{{ route.query.t }}</code>
+ <br />
+ hash: <code id="hash">{{ route.hash }}</code>
+ </p>
+
<router-view></router-view>
</div>
</body>
import { RouteComponent } from '../../src/types'
import { createApp } from 'vue'
-const component: RouteComponent = {
- template: `<div>A component</div>`,
-}
-
const Home: RouteComponent = {
- template: `<div>Home</div>`,
+ template: `<div>home</div>`,
}
-const Document: RouteComponent = {
+const Foo: RouteComponent = { template: '<div>foo</div>' }
+const Bar: RouteComponent = { template: '<div>bar</div>' }
+
+const Unicode: RouteComponent = {
setup() {
const route = useRoute()
return { route }
},
- template: `<div>Document: {{ route.params.id }}</div>`,
+ template: `<div>param: <span id="param">{{ route.params.id }}</span></div>`,
}
const router = createRouter({
history: createWebHashHistory('/' + __dirname),
routes: [
- { path: '/', component: Home, name: 'home' },
- { path: '/documents/:id', name: 'docs', component: Document },
- { path: encodeURI('/n/€'), name: 'euro', component },
+ { path: '/', component: Home },
+ { path: '/foo', component: Foo },
+ { path: '/bar', component: Bar },
+ { path: '/unicode/:id', name: 'unicode', component: Unicode },
+ { path: encodeURI('/n/é'), name: 'encoded', component: Foo },
],
})
})
app.use(router)
+window.r = router
window.vm = app.mount('#app')
--- /dev/null
+const bsStatus = require('../browserstack-send-status')
+
+const baseURL = 'http://localhost:8080/hash/#'
+
+module.exports = {
+ ...bsStatus(),
+
+ '@tags': ['hash', 'encoding'],
+
+ /** @type {import('nightwatch').NightwatchTest} */
+ 'navigating to links': function(browser) {
+ browser
+ .url(baseURL)
+ .waitForElementVisible('#app', 1000)
+ .assert.attributeContains('li:nth-child(1) a', 'href', '/hash/#/')
+ .assert.attributeContains('li:nth-child(2) a', 'href', '/hash/#/foo')
+ .assert.attributeContains('li:nth-child(3) a', 'href', '/hash/#/bar')
+ .assert.attributeContains('li:nth-child(4) a', 'href', '/hash/#/n/%C3%A9')
+ .assert.attributeContains(
+ 'li:nth-child(5) a',
+ 'href',
+ '/hash/#/unicode/%C3%A9'
+ )
+ .click('li:nth-child(3) a')
+ .assert.urlEquals(baseURL + '/bar')
+ .click('li:nth-child(2) a')
+ .assert.urlEquals(baseURL + '/foo')
+ .click('li:nth-child(4) a')
+ .assert.urlEquals(baseURL + '/n/%C3%A9')
+ .assert.containsText('#path', '/n/%C3%A9')
+
+ // the correctly encoded version
+ .click('li:nth-child(6) a')
+ .assert.urlEquals(baseURL + '/unicode/%C3%A9')
+ .assert.containsText('#path', '/unicode/%C3%A9')
+ .assert.containsText('#param', 'é')
+ // the unencoded version, no check for the url because changes based on browser
+ .click('li:nth-child(5) a')
+ .assert.containsText('#param', 'é')
+
+ .end()
+ },
+
+ /** @type {import('nightwatch').NightwatchTest} */
+ 'encoding on initial navigation': function(browser) {
+ browser
+ .url(baseURL + '/unicode/é')
+ // navigation to unencoded value
+ // depending on the browser the value will be encoded or not
+ .assert.containsText('#param', 'é')
+ .url(baseURL + '/unicode/%C3%A9')
+ // navigation to unencoded value
+ .assert.urlEquals(baseURL + '/unicode/%C3%A9')
+ .assert.containsText('#path', '/unicode/%C3%A9')
+ .assert.containsText('#param', 'é')
+
+ .end()
+ },
+}