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

activeClassName doesn't show up on pre-rendered pages #418

Open
orangecoloured opened this issue Jan 26, 2022 · 1 comment
Open

activeClassName doesn't show up on pre-rendered pages #418

orangecoloured opened this issue Jan 26, 2022 · 1 comment

Comments

@orangecoloured
Copy link

As the title says, links don't have the active class name appended in pre-rendered pages code. When I start to navigate everything works as it should.

@orangecoloured
Copy link
Author

orangecoloured commented Jan 27, 2022

Some additional data.

Here's my prerender-urls.js

const defaultMeta = {
	title: 'Title',
	description: 'Test',
}

module.exports = async () => {
	return [
		{
			url: '/',
			...defaultMeta,
		},
		{
			url: '/me',
			...defaultMeta,
			title: `Me / ${defaultMeta.title}`,
		},
		{
			url: '/experiments',
			...defaultMeta,
			title: `Experiments / ${defaultMeta.title}`,
		},
		{
			url: '/graphics',
			...defaultMeta,
			title: `Graphics / ${defaultMeta.title}`,
		},
	]
}

For a test I wrapped my links with <Match>

<Match path="/">{(props: any) => (
    <Fragment>
        <span>{JSON.stringify(props)}</span>
        <Link href="/experiments" class={`${className}${props.url.startsWith('/experiments') ? ' active' : ''}`} onClick={onClick}>Experiments</Link>
        <Link href="/graphics" class={`${className}${props.url.startsWith('/graphics') ? ' active' : ''}`} onClick={onClick}>Graphics</Link>
        <Link href="/me" class={`${className}${props.url.startsWith('/me') ? ' active' : ''}`} onClick={onClick}>Me</Link>
    </Fragment>
)}</Match>

After building the project I noticed that props contains data from the previous page.

{ "url": "/", "matches": true } -> "/"
{ "url": "/", "path": "/", "matches": true } -> "/me"
{ "url": "/me", "path": "/me", "matches": false } -> "/experiments"
{ "url": "/experiments", "path": "/experiments", "matches": false } -> "/graphics"

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

1 participant