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

Links doesn't work properly with history: createWebHistory #272

Closed
sametsafak opened this issue Jan 24, 2022 · 5 comments
Closed

Links doesn't work properly with history: createWebHistory #272

sametsafak opened this issue Jan 24, 2022 · 5 comments

Comments

@sametsafak
Copy link

When I switch router mode from hash to web history and try to access any page from sidebar or breadcrumb, app downloads all of the files again and again like opened from scratch. It works like old non single page applications.

But when I put a router link myself like:
<router-link to="/dashboard">hello</router-link>
It works normally. Loads only page related files.

  • Mac OS Monterey
  • Chrome 97.0.4692.99 Arm
@sametsafak
Copy link
Author

sametsafak commented Jan 29, 2022

I checked AppSidebarNav.js and set custom prop to false in h function that creates RouterLink.
It solves 2 problems and creates 2 problems.

Solved problems:
1- createWebHistory is working well. I can use template's routes without that # sign.
2- router.beforeEach was triggered twice before I set 'custom' prop to false. Now it triggers only once. Noice.

Created problems:
1- custom prop's definition in node_modules>vue router>...RouterLink says:
Whether RouterLink should not wrap its content in an a tag. Useful when using v-slot to create a custom RouterLink
Therefore now all sidebar li tags are wrapped in a tag. It is not a valid html (ul>a>li) but also it seems doesn't affect anything badly (except styles, i removed underline of li's wrapper a with css)
2- breadcrumb and other components that has router-link are working like my first comment. i guess they all have this custom property :(

@zeeforum
Copy link

In AppSidebarNav.js code is look like this:

{
	default: (props) => h(
		resolveComponent(item.component),
		{
			active: props.isActive,
			href: props.href,
			onClick: () => props.navigate(),
		},
		{
			default: () => [
			item.icon &&
				h(resolveComponent('CIcon'), {
				customClassName: 'nav-icon',
				name: item.icon,
				}),
			item.name,
			item.badge &&
				h(
				CBadge,
				{
					class: 'ms-auto',
					color: item.badge.color,
				},
				{
					default: () => item.badge.text,
				},
				),
			],
		},
	),
},

You can customize the child item using render function h. Here is my code that does the trick:

{
	default: (props) => h(
		resolveComponent(item.component),
		{
			active: props.isActive,
		},
		{
			default: () =>  h(
				RouterLink,
				{
					to: props.href,
					class: 'nav-link',
					onClick: () => props.navigate(),
				},
				{
					default: () => [
					item.icon &&
						h(resolveComponent('CIcon'), {
						customClassName: 'nav-icon',
						name: item.icon,
						}),
					item.name,
					item.badge &&
						h(
						CBadge,
						{
							class: 'ms-auto',
							color: item.badge.color,
						},
						{
							default: () => item.badge.text,
						},
						),
					],
				},
			),
		},
	),
},

I have removed href and onClick props from the original code. And shifted them into RouterLink render function and href converted to "to" attribute for RouterLink. For css added the class nav-link.

That does the trick.
Hope it helps.

@sametsafak
Copy link
Author

@zeeforum Yes it helped, thank you!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

@rofequl
Copy link

rofequl commented May 5, 2024

Links doesn't work properly with history: createWebHistory
The issue not resolved yet.

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

No branches or pull requests

3 participants