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

Router hooks #880

Open
ansarizafar opened this issue Nov 30, 2023 · 0 comments
Open

Router hooks #880

ansarizafar opened this issue Nov 30, 2023 · 0 comments

Comments

@ansarizafar
Copy link

I am trying to use Imba once again and stuck again with the router. I understand router is not designed for SPAs but Imba could be a great framework for SPAs.

With @haikyuu help I am able to get route-based code splitting working with Vite.

tag page-route
	prop url
	prop component
	resolvedPage = null
	
	def routed
		resolvedPage = await component()
	
	<self route=url>
		if resolvedPage
			<{resolvedPage.default}> 
		else
			<span [c:red5 fs:20px p:15px]> "Loading ..." if router.path === url

# About page
export default tag About
	<self>
		<h1> "About Page"
		<input value="Zafar">
		<a [c:green5 ] route-to="/"> "Go Home"

# Main.imba
<page-route url="/about" component=(do import("./About.imba")) >

The problem is that routed function is not always called and so not suitable for lazy loading routes and routes guards. Other framework routers like Vue router have comprehensive support for router hooks https://router.vuejs.org/guide/advanced/navigation-guards.html and svelte like onNavigate hook for view transitions https://kit.svelte.dev/docs/faq#how-do-i-use-the-view-transitions-api-with-sveltekit

@somebee I know router is not your priority, but I would request you to please consider adding these hooks to router.

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