Page wont redirect after parameter change
The order of my files is shown in the picture.
I'm trying to have two url Parameters:
http://localhost:3000/dashboard/324141341234134/2312341351234
The dashboard index.vue is there to choose the first element from which I want to put the id in my url (http://localhost:3000/dashboard/324141341234134
), then there will be child components where the user can choose, the id of the chose element should also be displayed in the url (http://localhost:3000/dashboard/324141341234134/2312341351234
)
My problem is, that the second redirect wont actually open the [channelid].vue:
The parameter is added in the url but the page remains the same. [channelid].vue only displayed if I refresh the page.
Does anyone know why this happens or how I can change the behaviour?24 Replies
Where are you getting
this.serverId
and this.channelId
from? Shouldn’t those be accessed from this.$route.params
?
Also, I think you mean .servId
instead of .serverId
since channelId
is nested inside servId
Which page is the code snippet from? channelId.vue?The code is from the [serverId].vue
Actually its passed through with this into a sub component:
And then passed further via props, the
channelId
depends on the button which the user clicks in the component
those are the sub components
You’d want to use a computed value for the serverId
Set the serverId in the computed properties instead so that reactivity isn’t lost
Alright I'll try to figure that out, thanks for your advice
reactivity on the
serverId
is lost when you do this. So further updates to the route params do not re-render the component.
what you instead want to do is this
I've changed the files now:
But its still not redirecting the page to the [channelId].vue
based on your directory structure, this isn't going to work
you're prolly in the wrong file
[servId].vue
happens to be the parent of [channelId].vue
. whereas [serverId].vue
is where you're making the changes (based on the first code snippet) which isn't related to [channelId].vue
the way I see it the [servId]
page doesn't existYeah so the [servId] folder is the there to make the two URL parameters possible, if I name the folder [serverId] then the code wont work at all. Its currently working after a refresh.
that's interesting. what's your url looking like in the address bar?
This one?
http://localhost:3000/dashboard/324141341234134/2312341351234
Its basically if I call http://localhost:3000/dashboard/324141341234134/
then the [serverId].vue
component is redirected
and if I press the button there which should redirect me to the [channelId].vue
then the url looks like this http://localhost:3000/dashboard/324141341234134/2312341351234
but its not redirecting. However if I refresh the page now then the [channelId].vue
component is displayedokay. gimme a moment
sure
How does stackblitz work?
There is only a 404 Page for me
Ill try to implement your code into mine
The window on the right is the preview screen. You can change the url in the address bar there
I've changed the order of the files to following now:
I also changed it here:
https://stackblitz.com/edit/github-ho2su4-dhgfkw?file=pages%2Fdashboard%2Findex.vue,components%2Fserver.vue,pages%2Fdashboard%2F[serverId]%2Findex.vue,pages%2Fdashboard%2F[serverId]%2F[channelId]%2Findex.vue,components%2Fservers.vue,components%2Fchannels.vue,components%2Fchannel.vue
But the behaviour did not change
I'm a little bit lost, I dont get where my mistake is
aaah I see what you're trying to achieve. will suggest a few changes soon
thanks
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
There is a
index.vue
file, I just did'nt mention itAh yeah you are right
Ill try it tomorrow, thanks in advance
I realized that there is an error in the code... which is only thrown on redirect, not thrown on refresh.... so thats why it did not work lol.
I just wasted about 3 days for a fricking semicolon in the html code
After removing the the semicolon, the code works flawless
I hate myself rn
Hahaa. It happens
You should not at all. It happens often. 😊
Whenever you are unable to redirect to a page manually and everything looks fine, there's probably an error in that page.vue blocking navigation