Skip to content
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

How to pass active url into template component #42

Closed
ruslankonev opened this issue Apr 17, 2021 · 4 comments
Closed

How to pass active url into template component #42

ruslankonev opened this issue Apr 17, 2021 · 4 comments

Comments

@ruslankonev
Copy link

Hi, at first thanks for your job!
But I have some question about pass some routing props into components to render active link or etc.

As example, I have a navigation component with set of links, and one of link need to have an active class.

Via Vue-Router I have a global props $router or $route.path into templates scope, but I don't know how to do that with your tool.

<a  :class="{active: $route.path === href }" ></a>
@brillout
Copy link
Member

The URL is available at contextProps.url and you can pass it to the browser by adding it to passToClient.

// _default.page.server.js

export const passToClient = ['pageProps', 'url'];

You can then pass contextProps.url to all your components with https://v3.vuejs.org/api/application-api.html#provide or https://v3.vuejs.org/guide/migration/global-api.html#vue-prototype-replaced-by-config-globalproperties. If you use Vue 2: https://vuejs.org/v2/cookbook/adding-instance-properties.html#Base-Example.

Does that work for you?

@ruslankonev
Copy link
Author

I will try, thanks

brillout added a commit that referenced this issue Apr 19, 2021
…lable everywhere (fix #42, fix #42)

BREAKING CHANGE: `contextProps.url` and `contextProps.urlNormalized` are deprecated: use `contextProps.urlFull` and `contextProps.urlPathname` instead.
brillout added a commit that referenced this issue Apr 19, 2021
@gryphonmyers
Copy link
Contributor

FYI a full integration with Vue Router is in progress.

brillout added a commit that referenced this issue Apr 21, 2021
…lable everywhere (fix #42, fix #42)

BREAKING CHANGE: `contextProps.url` and `contextProps.urlNormalized` are deprecated: use `contextProps.urlFull` and `contextProps.urlPathname` instead.
brillout added a commit that referenced this issue Apr 21, 2021
brillout added a commit that referenced this issue Apr 21, 2021
@brillout
Copy link
Member

See https://github.com/brillout/vite-plugin-ssr#active-links-a-classis-active.

Note that contextProps.url is depcrated; use contextProps.urlPathname or contextProps.urlFull instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants