Nuxt.js: How to use the same page with different URLs and switch the components to be displayed according to the URLHow do I modify the URL without reloading the page?How to use vue-infinite-loading in Nuxt.js (Vue.js)How to redirect to a different url inside the vue-router beforeRouteEnter hook?SyntaxError: Unexpected token < when trying to test with AVAHow to submit a form in Vue, redirect to a new route and pass the parameters?Nuxt.js – Nuxt generate does not pass onclick parameter to component on 404 pageUsing Vue Design System in Nuxt is throwing errors about export in system.jsRedirecting to the same page but switched language url, using Nuxt.js and Vue-i18nComputed Getter causes maximum stack size errorRun nuxt on https locally – problem with nuxt.config.js
std::tuple sizeof, is it a missed optimization?
How to encode a class with 24,000 categories?
How to find better food in airports
Count rook moves 1D
Can I sleep overnight at Stansted Airport
What drugs were used in England during the High Middle Ages?
Which is the best password hashing algorithm in .NET Core?
Does this bike use hydraulic brakes?
Why did the Joi advertisement trigger K?
How will the UK Commons debate tonight despite the prorogation?
Did Alan Turing's student Robin Gandy assert that Charles Babbage had no notion of a universal computing machine?
Case Studies and Real Problems for Teaching Optimization and Modelling
Finder/Terminal: Find files that contain less than 21 lines of text
Does immunity to damage from nonmagical attacks negate a rogue's Sneak Attack damage?
What does "se jouer" mean here?
What happens if I double Meddling Mage's 'enter the battlefield' trigger?
How do I stop making people jump at home and at work?
Question about derivation of kinematics equations
Travel to USA with a stuffed puppet
How many days for hunting?
Planet that’s 90% water or more?
Punishment in pacifist society
When is it legal to castle moving the rook first?
'Hard work never hurt anyone' Why not 'hurts'?
Nuxt.js: How to use the same page with different URLs and switch the components to be displayed according to the URL
How do I modify the URL without reloading the page?How to use vue-infinite-loading in Nuxt.js (Vue.js)How to redirect to a different url inside the vue-router beforeRouteEnter hook?SyntaxError: Unexpected token < when trying to test with AVAHow to submit a form in Vue, redirect to a new route and pass the parameters?Nuxt.js – Nuxt generate does not pass onclick parameter to component on 404 pageUsing Vue Design System in Nuxt is throwing errors about export in system.jsRedirecting to the same page but switched language url, using Nuxt.js and Vue-i18nComputed Getter causes maximum stack size errorRun nuxt on https locally – problem with nuxt.config.js
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to implement the following in Nuxt.js:
1.Use the same page with different URLs.
Specifically, I want to use /pages/users/_userId.vue
with/users/userId
, /users/userId/follow
and /users/userId/follower
.
I examined this and there were the following issues.
- https://github.com/nuxt/nuxt.js/issues/2693
But it was a little different from what I wanted to achieve.
I want to use the pass parameter for the query parameter.
2.Identify the components to display by path parameters
It would be quicker to have a look at the code here.
・/pages/users/_userId.vue`
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo/>
<PostSection/> -> use if URL /users /userId
<FollowSection/> -> use if URL /users/userId/follow
<FollowerSection/> -> use if URL /users/userId/follower
</div>
</div>
</div>
</template>
<script>
import UserInfo from '~/components/organisms/users/UserInfo'
import PostsSection from '~/components/organisms/users/PostsSection'
import FollowSection from '~/components/organisms/users/FollowSection'
import FollowerSection from '~/components/organisms/users/FollowerSection'
...
What should I do to achieve these?
javascript vue.js nuxt.js
add a comment |
I want to implement the following in Nuxt.js:
1.Use the same page with different URLs.
Specifically, I want to use /pages/users/_userId.vue
with/users/userId
, /users/userId/follow
and /users/userId/follower
.
I examined this and there were the following issues.
- https://github.com/nuxt/nuxt.js/issues/2693
But it was a little different from what I wanted to achieve.
I want to use the pass parameter for the query parameter.
2.Identify the components to display by path parameters
It would be quicker to have a look at the code here.
・/pages/users/_userId.vue`
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo/>
<PostSection/> -> use if URL /users /userId
<FollowSection/> -> use if URL /users/userId/follow
<FollowerSection/> -> use if URL /users/userId/follower
</div>
</div>
</div>
</template>
<script>
import UserInfo from '~/components/organisms/users/UserInfo'
import PostsSection from '~/components/organisms/users/PostsSection'
import FollowSection from '~/components/organisms/users/FollowSection'
import FollowerSection from '~/components/organisms/users/FollowerSection'
...
What should I do to achieve these?
javascript vue.js nuxt.js
add a comment |
I want to implement the following in Nuxt.js:
1.Use the same page with different URLs.
Specifically, I want to use /pages/users/_userId.vue
with/users/userId
, /users/userId/follow
and /users/userId/follower
.
I examined this and there were the following issues.
- https://github.com/nuxt/nuxt.js/issues/2693
But it was a little different from what I wanted to achieve.
I want to use the pass parameter for the query parameter.
2.Identify the components to display by path parameters
It would be quicker to have a look at the code here.
・/pages/users/_userId.vue`
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo/>
<PostSection/> -> use if URL /users /userId
<FollowSection/> -> use if URL /users/userId/follow
<FollowerSection/> -> use if URL /users/userId/follower
</div>
</div>
</div>
</template>
<script>
import UserInfo from '~/components/organisms/users/UserInfo'
import PostsSection from '~/components/organisms/users/PostsSection'
import FollowSection from '~/components/organisms/users/FollowSection'
import FollowerSection from '~/components/organisms/users/FollowerSection'
...
What should I do to achieve these?
javascript vue.js nuxt.js
I want to implement the following in Nuxt.js:
1.Use the same page with different URLs.
Specifically, I want to use /pages/users/_userId.vue
with/users/userId
, /users/userId/follow
and /users/userId/follower
.
I examined this and there were the following issues.
- https://github.com/nuxt/nuxt.js/issues/2693
But it was a little different from what I wanted to achieve.
I want to use the pass parameter for the query parameter.
2.Identify the components to display by path parameters
It would be quicker to have a look at the code here.
・/pages/users/_userId.vue`
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo/>
<PostSection/> -> use if URL /users /userId
<FollowSection/> -> use if URL /users/userId/follow
<FollowerSection/> -> use if URL /users/userId/follower
</div>
</div>
</div>
</template>
<script>
import UserInfo from '~/components/organisms/users/UserInfo'
import PostsSection from '~/components/organisms/users/PostsSection'
import FollowSection from '~/components/organisms/users/FollowSection'
import FollowerSection from '~/components/organisms/users/FollowerSection'
...
What should I do to achieve these?
javascript vue.js nuxt.js
javascript vue.js nuxt.js
asked Mar 28 at 3:10
xKxAxKxxKxAxKx
3771 gold badge4 silver badges20 bronze badges
3771 gold badge4 silver badges20 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
As the displayed components depends on the current route, you can use the router.
Namely using the nuxtjs nested routes feature. (example of dynamic nested routes in nuxtjs docs)
pages/
--| users/
-----| _id/
--------| follow.vue // contains FollowSection
--------| follower.vue // contains FollowerSection
--------| index.vue // contains UserProfile
-----| _id.vue
// users/_id.vue
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo>
<NuxtChild
:user="user"
@custom-event="customEventHandler"
/>
</div>
</div>
</div>
<template>
You can reuse the components as nested pages like that:
// pages/users/_id/follower.vue
<script>
// don't create a template for the section
import FollowSection from '~/components/organisms/users/FollowSection'
export FollowSection
</script>
Note that you don't need to import the child components in _id.vue
because nuxt configure vue-router to do so. Also that you can pass props and send events to them like normal components.
add a comment |
All your paths have a common prefix users/
. So you can use the pages/users/_.vue
component to match any path starting with the users/
that was not matched to any other component.
In this component you can examine $nuxt.$route.params.pathMatch
to decide, which subcomponent to show. It will contain part of path after users/
:
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo />
<PostSection v-if="/^d+$/.test(path)" />
<FollowSection v-else-if="/^d+/follow$/.test(path)" />
<FollowerSection v-else-if="/^d+/follower$/.test(path)" />
</div>
</div>
</div>
</template>
<script>
export default
computed:
path()
return this.$nuxt.$route.params.pathMatch;
,
,
...
;
</script>
add a comment |
Instead of one page , you can create individual page by setting your project directory structrue like this . It will more easy to handle and modify
pages/
--| users/
-----| _id/
--------| follow.vue
--------| follower.vue
-----| _id.vue
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389600%2fnuxt-js-how-to-use-the-same-page-with-different-urls-and-switch-the-components%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
As the displayed components depends on the current route, you can use the router.
Namely using the nuxtjs nested routes feature. (example of dynamic nested routes in nuxtjs docs)
pages/
--| users/
-----| _id/
--------| follow.vue // contains FollowSection
--------| follower.vue // contains FollowerSection
--------| index.vue // contains UserProfile
-----| _id.vue
// users/_id.vue
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo>
<NuxtChild
:user="user"
@custom-event="customEventHandler"
/>
</div>
</div>
</div>
<template>
You can reuse the components as nested pages like that:
// pages/users/_id/follower.vue
<script>
// don't create a template for the section
import FollowSection from '~/components/organisms/users/FollowSection'
export FollowSection
</script>
Note that you don't need to import the child components in _id.vue
because nuxt configure vue-router to do so. Also that you can pass props and send events to them like normal components.
add a comment |
As the displayed components depends on the current route, you can use the router.
Namely using the nuxtjs nested routes feature. (example of dynamic nested routes in nuxtjs docs)
pages/
--| users/
-----| _id/
--------| follow.vue // contains FollowSection
--------| follower.vue // contains FollowerSection
--------| index.vue // contains UserProfile
-----| _id.vue
// users/_id.vue
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo>
<NuxtChild
:user="user"
@custom-event="customEventHandler"
/>
</div>
</div>
</div>
<template>
You can reuse the components as nested pages like that:
// pages/users/_id/follower.vue
<script>
// don't create a template for the section
import FollowSection from '~/components/organisms/users/FollowSection'
export FollowSection
</script>
Note that you don't need to import the child components in _id.vue
because nuxt configure vue-router to do so. Also that you can pass props and send events to them like normal components.
add a comment |
As the displayed components depends on the current route, you can use the router.
Namely using the nuxtjs nested routes feature. (example of dynamic nested routes in nuxtjs docs)
pages/
--| users/
-----| _id/
--------| follow.vue // contains FollowSection
--------| follower.vue // contains FollowerSection
--------| index.vue // contains UserProfile
-----| _id.vue
// users/_id.vue
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo>
<NuxtChild
:user="user"
@custom-event="customEventHandler"
/>
</div>
</div>
</div>
<template>
You can reuse the components as nested pages like that:
// pages/users/_id/follower.vue
<script>
// don't create a template for the section
import FollowSection from '~/components/organisms/users/FollowSection'
export FollowSection
</script>
Note that you don't need to import the child components in _id.vue
because nuxt configure vue-router to do so. Also that you can pass props and send events to them like normal components.
As the displayed components depends on the current route, you can use the router.
Namely using the nuxtjs nested routes feature. (example of dynamic nested routes in nuxtjs docs)
pages/
--| users/
-----| _id/
--------| follow.vue // contains FollowSection
--------| follower.vue // contains FollowerSection
--------| index.vue // contains UserProfile
-----| _id.vue
// users/_id.vue
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo>
<NuxtChild
:user="user"
@custom-event="customEventHandler"
/>
</div>
</div>
</div>
<template>
You can reuse the components as nested pages like that:
// pages/users/_id/follower.vue
<script>
// don't create a template for the section
import FollowSection from '~/components/organisms/users/FollowSection'
export FollowSection
</script>
Note that you don't need to import the child components in _id.vue
because nuxt configure vue-router to do so. Also that you can pass props and send events to them like normal components.
edited Jul 17 at 18:02
answered Jul 17 at 17:33
mutasakimutasaki
1,0276 silver badges16 bronze badges
1,0276 silver badges16 bronze badges
add a comment |
add a comment |
All your paths have a common prefix users/
. So you can use the pages/users/_.vue
component to match any path starting with the users/
that was not matched to any other component.
In this component you can examine $nuxt.$route.params.pathMatch
to decide, which subcomponent to show. It will contain part of path after users/
:
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo />
<PostSection v-if="/^d+$/.test(path)" />
<FollowSection v-else-if="/^d+/follow$/.test(path)" />
<FollowerSection v-else-if="/^d+/follower$/.test(path)" />
</div>
</div>
</div>
</template>
<script>
export default
computed:
path()
return this.$nuxt.$route.params.pathMatch;
,
,
...
;
</script>
add a comment |
All your paths have a common prefix users/
. So you can use the pages/users/_.vue
component to match any path starting with the users/
that was not matched to any other component.
In this component you can examine $nuxt.$route.params.pathMatch
to decide, which subcomponent to show. It will contain part of path after users/
:
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo />
<PostSection v-if="/^d+$/.test(path)" />
<FollowSection v-else-if="/^d+/follow$/.test(path)" />
<FollowerSection v-else-if="/^d+/follower$/.test(path)" />
</div>
</div>
</div>
</template>
<script>
export default
computed:
path()
return this.$nuxt.$route.params.pathMatch;
,
,
...
;
</script>
add a comment |
All your paths have a common prefix users/
. So you can use the pages/users/_.vue
component to match any path starting with the users/
that was not matched to any other component.
In this component you can examine $nuxt.$route.params.pathMatch
to decide, which subcomponent to show. It will contain part of path after users/
:
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo />
<PostSection v-if="/^d+$/.test(path)" />
<FollowSection v-else-if="/^d+/follow$/.test(path)" />
<FollowerSection v-else-if="/^d+/follower$/.test(path)" />
</div>
</div>
</div>
</template>
<script>
export default
computed:
path()
return this.$nuxt.$route.params.pathMatch;
,
,
...
;
</script>
All your paths have a common prefix users/
. So you can use the pages/users/_.vue
component to match any path starting with the users/
that was not matched to any other component.
In this component you can examine $nuxt.$route.params.pathMatch
to decide, which subcomponent to show. It will contain part of path after users/
:
<template>
<div class="user">
<div class="user__contents">
<div class="user__contents__main">
<UserInfo />
<PostSection v-if="/^d+$/.test(path)" />
<FollowSection v-else-if="/^d+/follow$/.test(path)" />
<FollowerSection v-else-if="/^d+/follower$/.test(path)" />
</div>
</div>
</div>
</template>
<script>
export default
computed:
path()
return this.$nuxt.$route.params.pathMatch;
,
,
...
;
</script>
answered Jul 17 at 18:42
Nina LisitsinskayaNina Lisitsinskaya
6982 silver badges12 bronze badges
6982 silver badges12 bronze badges
add a comment |
add a comment |
Instead of one page , you can create individual page by setting your project directory structrue like this . It will more easy to handle and modify
pages/
--| users/
-----| _id/
--------| follow.vue
--------| follower.vue
-----| _id.vue
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
add a comment |
Instead of one page , you can create individual page by setting your project directory structrue like this . It will more easy to handle and modify
pages/
--| users/
-----| _id/
--------| follow.vue
--------| follower.vue
-----| _id.vue
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
add a comment |
Instead of one page , you can create individual page by setting your project directory structrue like this . It will more easy to handle and modify
pages/
--| users/
-----| _id/
--------| follow.vue
--------| follower.vue
-----| _id.vue
Instead of one page , you can create individual page by setting your project directory structrue like this . It will more easy to handle and modify
pages/
--| users/
-----| _id/
--------| follow.vue
--------| follower.vue
-----| _id.vue
answered Mar 28 at 4:21
デビットデビット
813 bronze badges
813 bronze badges
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
add a comment |
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
That is not an optimal solution. Having the same .vue page twice is difficult to maintain.
– Bill Souvas
Jul 15 at 6:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389600%2fnuxt-js-how-to-use-the-same-page-with-different-urls-and-switch-the-components%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown