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

Mithril not respecting base href #2377

Closed
volnei opened this issue Feb 12, 2019 · 6 comments
Closed

Mithril not respecting base href #2377

volnei opened this issue Feb 12, 2019 · 6 comments
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions

Comments

@volnei
Copy link

volnei commented Feb 12, 2019

Mithril Version: 2.0.0-rc3

2.0.0-rc3

Im developing a multi language app using mithril where witch language have your directory. Eg.: /en/ /pt/ etc.

When running the application using Nginx and following http://localhost/pt/ the navigator is redirected to http://localhost.

The html file is:

<!DOCTYPE html>
<html>
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="x-ua-compatible" content="ie=edge; chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
		
		<title>...</title>

		<base href="/pt/"/>

		<link rel="icon" href="/img/favicon.ico">
		<meta name="theme-color" content="#E64545">
		<link href="https://fonts.googleapis.com/css?family=Montserrat:100,300,400,500,600" rel="stylesheet">
	<link href="main.d819cfc3a0cfab094b29.css" rel="stylesheet"></head>
	<body>
		<main id="main"></main>
	<script type="text/javascript" src="92f025ccf65eb904ad80.bundle.js"></script><script type="text/javascript" src="main.64bdb34fc2a6a3597db4.js"></script></body>
</html>

And the mithril config is:

m.route.prefix("")
m.route(document.querySelector("#main"), "/", {
	"/": layout(site),
	"/login": layout(login)
}

But in browser, the lang part for url is not respected and its automatically redirected to /.

Can anyone help me?

Thanks

@barneycarroll
Copy link
Member

Hi @volnei! When using non-prefixed route mode, you will need to include the entire path for each route. If you want to prefix your Mithril routes with whatever path the page resolved on, you can access the current path with location.pathname.

@volnei
Copy link
Author

volnei commented Feb 12, 2019

@barneycarroll thanks for your quick response!! So, I need to map and reference the /lang part in any of my routes and links?

Like this?

m.route.prefix("")
m.route(document.querySelector("#main"), "/en/", {
	"/en/": layout(site),
	"/en/login": layout(login)
}

Theres no way to make it more generic?

@barneycarroll
Copy link
Member

I think so. I thought for a moment it would be possible to put the language prefix as m.route.prefix('/en'), but apparently not… 😕

@volnei
Copy link
Author

volnei commented Feb 12, 2019

Yes, I've tried this a minute ago, but not work too.
Would not it be correct for mithril itself to be based on the href in base directive? React for example have a base path where we can configure this. Any change to make this topic a feature request?

@ChrisGitIt
Copy link

ChrisGitIt commented Feb 14, 2019

Hi @volnei ,

i'm not sure what you are going to achieve, but can't you use just language placeholders and drop the whole "base href"? So

m.route(doc_root, "/", {
  "/:lang/": ..
  "/:lang/login": ...
})

Within your app, you will get vnode.attrs.lang as an interpolated value from ":lang" definition within the routes.

@dead-claudia dead-claudia added the Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions label Apr 17, 2019
@dead-claudia
Copy link
Member

Closing due to age.

@dead-claudia dead-claudia closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions
Projects
None yet
Development

No branches or pull requests

4 participants