22// import ParentLayout from '@vuepress/theme-default/layouts/Layout.vue'
33import { Layout as ParentLayout , PageContent } from ' vuepress-theme-hope/client'
44import { useRoute , useRouter } from " vue-router" ;
5- import { ref } from ' vue'
5+ import { ref , onMounted } from ' vue'
66
77const version = ref (" " );
88
@@ -11,8 +11,10 @@ function setVersionBasedOnCurrentPath() : void {
1111 if (route .path .startsWith (' /operations/' )) {
1212 const input = route .path .substring (' /operations/' .length );
1313 const firstSlash = input .indexOf (" /" );
14- const result = firstSlash !== - 1 ? input .slice (0 , firstSlash ) : input ;
15-
14+ var result = firstSlash !== - 1 ? input .slice (0 , firstSlash ) : input ;
15+ if (result === " latest" ) {
16+ result = document .querySelector (" #version-select > option[latest='true']" ).value ;
17+ }
1618 version .value = result ;
1719
1820
@@ -29,13 +31,20 @@ router.afterEach((_to, _from) => {
2931 setVersionBasedOnCurrentPath ();
3032});
3133
32- setVersionBasedOnCurrentPath ();
34+ onMounted (() => {
35+ setVersionBasedOnCurrentPath ();
36+ })
3337
3438function navigateToNewVersion() {
3539 const input = route .path .substring (' /operations/' .length );
3640 const firstSlash = input .indexOf (" /" );
3741 const result = firstSlash !== - 1 ? input .slice (firstSlash + 1 ) : " " ;
38- router .push (' /operations/' + version .value + " /" + result );
42+ if (version .value === document .querySelector (" #version-select > option[latest='true']" ).value ) {
43+ router .push (' /operations/' + " latest" + " /" + result );
44+ } else {
45+ router .push (' /operations/' + version .value + " /" + result );
46+
47+ }
3948}
4049
4150 </script >
@@ -46,8 +55,7 @@ function navigateToNewVersion() {
4655 <div class =" version-selector" v-if =" route.path.startsWith('/operations/')" >
4756 <label class =" vp-sidebar-header" for =" version-select" ><strong >Version:</strong > </label >
4857 <select id =" version-select" class =" vp-sidebar-header" v-model =" version" @change =" navigateToNewVersion" >
49- <option value =" next" >next (2.0.0-M3)</option >
50- <option value =" latest" >latest (1.8.0)</option >
58+ <option value =" v1.8.0" latest =" true" >latest (1.8.0)</option >
5159 <option value =" v1.7.1" >1.7.1</option >
5260 <option value =" v1.7.0" >1.7.0</option >
5361 <option value =" v1.6.0" >1.6.0</option >
@@ -61,6 +69,7 @@ function navigateToNewVersion() {
6169 <option value =" v1.2.0" >1.2.0</option >
6270 <option value =" v1.1.0" >1.1.0</option >
6371 <option value =" v1.0.0" >1.0.0</option >
72+ <option value =" v2.0.0-M3" >2.0.0-M3</option >
6473 </select ></div >
6574 </template >
6675 <PageContent id =" main-content" class =" vp-page" />
0 commit comments