-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable a component on some routes? #254
Comments
@joedawson I'm sure Vue provides many mechanisms to accomplish this. I believe the Now for the conditional expression to use with those directives you can utilize the First I would add names to my routes: router.map({
// ...
'/auth/login': { name: 'login', component: LoginView },
'/auth/register': { name: 'register', component: RegisterView },
// ...
}); Then you can just conditionally display the navigation based on the current route name: <navigation v-if="['login', 'register'].indexOf($route.name) > -1"></navigation> This is just one way, and I'm sure it can be cleaned up a bit. Though I would like to know if there is a potential best practice way to do this since I imagine this is a common pattern. |
@amirrustam I approached it a little differently in the end - I simply added a class to the body if the current route matched either
|
Cool. is their a best practice to this, i couldn't find anything in the vue cookbook. |
This will also work
|
What are the best practices for hiding/disabling a component on some routes? |
In the nav component listen to the route changes to update a flag whether the nav will be shown or hidden, you may check with route name or path: note: the following example uses typescript:
|
Route meta fields provide yet another option: const router = new VueRouter({
routes: [
{
path: '/foo',
component: Foo,
meta: { hideNavigation: true }
}
]
}) <navigation v-if="!$route.meta.hideNavigation" /> |
This question covers a useful thing to know in general, however if you want to show/hide certain main components like a header or footer, the best way is to simply create multiple layouts that include the components you want. |
Hide Header in some components using the current route path.get current route path using <navigation v-if="showNavigation"></navigation> data() {
this.$route.path === '/' ? this.showNavigation = false : this.showNavigation = true
} |
How can we achieve this in nuxt? |
For someone don't want to use |
Hello,
I'm not sure if this the correct way of thinking - but I want one of my components to be disabled or deactivated on some routes.
So here's my routes.
My main template file looks like so:
When I'm on either the
/auth/login
or/auth/register
routes - I do not want my navigation component to appear.How can I achieve this?
The text was updated successfully, but these errors were encountered: