Closed chyzwar closed 9 years ago
I don't understand what you're asking. Could you clarify?
When user type in url in browser address bar like: //hostname/login then accountant should try to match this to existing routes.
It does, if you have your secretary routes defined. That's like half the point of the library :stuck_out_tongue:
If you're not seeing that behavior, show me what you're doing with secretary and accountant, because it's probably configured wrong.
(ns ^:figwheel-always whisper.routes
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[secretary.core :as sec :refer-macros [defroute]]
[accountant.core :as accountant]))
(accountant/configure-navigation!)
(defn widget [data owner]
(reify
om/IRender
(render [this]
(dom/h1 nil (:text data)))))
(defroute main-page "/" []
(om/root widget {:text "Main Page"}
{:target (. js/document (getElementById "app"))})
(js/console.log (str "Main Page")))
(defroute login-page "/login" []
(om/root widget {:text "Login Page"}
{:target (. js/document (getElementById "app"))})
(js/console.log (str "Login Page")))
(defroute wildcard "*" []
(accountant/navigate! "/"))
(accountant/navigate! "/login")
Page start on "/login" , but when I change "/" I get empty page. Alternativly, When I start from / and change to /login I got page not found.
I use https://github.com/bhauman/figwheel-template
I just started with cljs, maybe I messed up :)
I do think having the navigate!
call there at the end is probably sub-optimal. What I have on load time is (secretary/dispatch! (.-pathname (.-location js/window)))
but that's your call.
The only other thing I can think is that your wildcard route is firing somehow. What actually happens when you try to load /login
? Does anything show up in the console?
When I start figwhell, page is loaded to /login route. But whenever I click on page area I get the error in screenshot. Strenge enough, error is only happen when I click on page.
When I remove /login from url leaving only http://localhost:3449 page is loaded but not root or wildcard route is triggered (no console logs) To see console.logs you need to add: (enable-console-print!)
Maybe it is figwhell related issue.
I now understand your issue. (accountant/navigate!) is intended for use as a reactor; it's not intended to be used in the initial page load. A better example of its use can be found here:
(defn go-to-repo-dashboard!
[username repo]
(accountant/navigate!
(string/format "/gh/%s/%s" username repo)))
Instead, you should use the initial dispatch! call that I pasted above for your initial page load:
(accountant/configure-navigation!)
(defn widget [data owner]
(reify
om/IRender
(render [this]
(dom/h1 nil (:text data)))))
(defroute main-page "/" []
(om/root widget {:text "Main Page"}
{:target (. js/document (getElementById "app"))})
(js/console.log (str "Main Page")))
(defroute login-page "/login" []
(om/root widget {:text "Login Page"}
{:target (. js/document (getElementById "app"))})
(js/console.log (str "Login Page")))
(defroute wildcard "*" []
(accountant/navigate! "/"))
(secretary/dispatch! (.-pathname (.-location js/window)))
I've tested this and it works great once you change it.
There's a good question here about whether accountant/navigate!
should do the thing you expect it to here, and to be totally honest I don't understand why it doesn't. I'll have to look into it further.
Actually, I take that back. accountant/navigate!
does work fine for me as well.
Okay, yeah, sorry, I'm completely unable to reproduce your issue. The code you've provided works fine on my machine.
thanks, for your time. This is probably related to figwheel ,like it loose state of history of something like that.
On Oct 22 2015, at 1:34 am, Ursa americanus kermodei <notifications@github.com> wrote:
Okay, yeah, sorry, I'm completely unable to reproduce your issue. The code you've provided works fine on my machine.
—
Reply to this email directly or view it on GitHub.
Hi
It should be possible to use secretary and accountant for routing when user type url manually?