When I click in a router-link to go to register-form page, the URL changes, but the ponent doesn´t load.
I have the navbar in a ponent, and I thought that it was wrong, but no...
Here's the router's file code:
import {createRouter, createWebHashHistory} from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
ponent: () => import(/* webpackChunkName: "home" */ '../views/Home.vue')
},
{
path: '/formulario-registro',
name: 'RegisterForm',
ponent: () => import(/*webpackChunkName: "registerform"*/ '../views/RegisterForm.vue')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
});
export default router
And here's my nav ponet, where there are the router-link:
<div class="nav">
<div class="brand">
<router-link to="/">BookArt</router-link>
</div>
<div class="collapse">
<span id="mobile-icon" v-on:click="responsiveNavbar"></span>
</div>
<div class="links">
<ul id="nav-list-group">
<li class="list-item">
<router-link to="/"> Inicio</router-link>
</li>
<li class="list-item">
<router-link to="/formulario-registro"> Registro</router-link>
</li>
<li class="list-item">
<router-link to=""> Login</router-link>
</li>
</ul>
</div>
My main.js code:
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App).use(store).use(router).mount('#app')
And my App.vue code:
<template>
<Nav></Nav>
<router-view/>
</template>
<script>
import Nav from '@/ponents/Nav.vue'
export default {
ponents: {
Nav
}
}
</script>
Here's my register-form ponent's code:
<template>
<form action="">
<div class="form-group">
<input type="text" name="form.username" id="form.username" class="username" placeholder="Nombre de usuario....">
</div>
<div class="form-group">
<input type="file" name="form.profile_pic" id="form.profile_pic" class="profile_pic"
placeholder="Foto de perfil....">
</div>
<div class="form-group">
<input type="email" name="form.email" id="form.email" class="email" placeholder="Email....">
</div>
<div class="form-group">
<input type="password" name="form.password" id="form.password" class="password" placeholder="*******">
</div>
<div class="form-group">
<input type="password" name="form.confirm_password" id="form.confirm.password" class="confirm_password"
placeholder="*******">
</div>
<div class="form-group">
<button>Registrarse</button>
</div>
</form>
</template>
<script>
export default {
name: "Register-form",
mounted() {
console.log('Its ok');
}
}
</script>
When I click in a router-link to go to register-form page, the URL changes, but the ponent doesn´t load.
I have the navbar in a ponent, and I thought that it was wrong, but no...
Here's the router's file code:
import {createRouter, createWebHashHistory} from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
ponent: () => import(/* webpackChunkName: "home" */ '../views/Home.vue')
},
{
path: '/formulario-registro',
name: 'RegisterForm',
ponent: () => import(/*webpackChunkName: "registerform"*/ '../views/RegisterForm.vue')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
});
export default router
And here's my nav ponet, where there are the router-link:
<div class="nav">
<div class="brand">
<router-link to="/">BookArt</router-link>
</div>
<div class="collapse">
<span id="mobile-icon" v-on:click="responsiveNavbar"></span>
</div>
<div class="links">
<ul id="nav-list-group">
<li class="list-item">
<router-link to="/"> Inicio</router-link>
</li>
<li class="list-item">
<router-link to="/formulario-registro"> Registro</router-link>
</li>
<li class="list-item">
<router-link to=""> Login</router-link>
</li>
</ul>
</div>
My main.js code:
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App).use(store).use(router).mount('#app')
And my App.vue code:
<template>
<Nav></Nav>
<router-view/>
</template>
<script>
import Nav from '@/ponents/Nav.vue'
export default {
ponents: {
Nav
}
}
</script>
Here's my register-form ponent's code:
<template>
<form action="">
<div class="form-group">
<input type="text" name="form.username" id="form.username" class="username" placeholder="Nombre de usuario....">
</div>
<div class="form-group">
<input type="file" name="form.profile_pic" id="form.profile_pic" class="profile_pic"
placeholder="Foto de perfil....">
</div>
<div class="form-group">
<input type="email" name="form.email" id="form.email" class="email" placeholder="Email....">
</div>
<div class="form-group">
<input type="password" name="form.password" id="form.password" class="password" placeholder="*******">
</div>
<div class="form-group">
<input type="password" name="form.confirm_password" id="form.confirm.password" class="confirm_password"
placeholder="*******">
</div>
<div class="form-group">
<button>Registrarse</button>
</div>
</form>
</template>
<script>
export default {
name: "Register-form",
mounted() {
console.log('Its ok');
}
}
</script>
Share
Improve this question
edited Nov 23, 2020 at 21:48
Boussadjra Brahim
1
asked Nov 23, 2020 at 19:06
ÁlvaroÁlvaro
3226 silver badges17 bronze badges
19
- please share the main.js and app.vue code – Boussadjra Brahim Commented Nov 23, 2020 at 19:11
- @BoussadjraBrahim I have added them. – Álvaro Commented Nov 23, 2020 at 19:14
- the code seems work, did you get errors in console? – Boussadjra Brahim Commented Nov 23, 2020 at 19:19
-
I get the a warning
runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at
and the following errorUncaught (in promise) RangeError: Maximum call stack size exceeded at renderComponentRoot
– Álvaro Commented Nov 23, 2020 at 19:21 -
1
All of this looks correct. So I'd love to see the
RegisterForm
code. "Stack size exceeded" indicates a possible infinite loop. – Kielstra Commented Nov 23, 2020 at 19:25
2 Answers
Reset to default 4The issue is in ../view/RegisterForm
ponent which renders itself :
<template>
<RegisterForm></RegisterForm><!-- this is the ponent itself not th child one-->
</template>
<script>
import RegisterForm from '@/ponents/Register-form';
export default {
ponents: {
RegisterForm
},
name: "RegisterForm"
}
</script>
<style scoped>
</style>
this generates an infinite loop, to solve this just change the name of imported ponent :
<template>
<RegisterForm1></RegisterForm1>
</template>
<script>
import RegisterForm1 from '@/ponents/RegisterForm1';
export default {
ponents: {
RegisterForm1
},
name: "RegisterForm"
}
</script>
<style scoped>
</style>
change in App.vue =>
<template>
<router-view />
</template>
<template>
<router-view :key="$route.path" />
</template>