funcool / bide Goto Github PK
View Code? Open in Web Editor NEWA simple routing library for ClojureScript
License: BSD 2-Clause "Simplified" License
A simple routing library for ClojureScript
License: BSD 2-Clause "Simplified" License
The following warning is generated when compiling with shadow-cljs, though everything seems to work fine otherwise.
------ WARNING #1 --------------------------------------------------------------
File: bide/impl/helpers.js:29:41
variable toString is undeclared
--------------------------------------------------------------------------------
https://github.com/funcool/bide/blob/master/src/bide/impl/helpers.js#L29
Hi,
In the README, there is an example:
(def routes
[["/auth/login" :auth/login]
["/auth/recovery/token/:token" :auth/recovery]
["/workspace/:project-uuid/:page-uuid" :workspace/page]])
but I've found that bide
doesn't currently work with hyphenated keywords like :project-uuid
and :page-uuid
. so:
(r/match router "/workspace/abc/def")
=> nil
Avoiding hyphenated keywords seems to do what we want.
(def routes
[...
["/workspace/:projectuuid/:pageuuid" :workspace/page]])
(r/match router "/workspace/abc/def")
=> [:workspace/page {:projectuuid "abc", :pageuuid "def"}]
I'm assuming you want bide to be able to use hyphenated url keywords, so I think you'll have to change the parser regex.
I'm calling navigate!
with the same route
and params
, but changing the 3rd argument, the query
, causes a new set of query params to be added to the end of the URL. (instead of clearing out the previous keys).
For example, from the README if I do
(r/navigate! router :myapp/user-by-id {:id 2} {:foobar 1})
;; => "/api/users/2?foobar=1"
(r/navigate! router :myapp/user-by-id {:id 2} {:foobar 2})
;; => "/api/users/2?foobar=1?foobar=2"
When using :html5? true
, the query gets appended to the the URL in the browser when using navigate!
. The following generates a url ending with ?show-fields=true?show-fields=false?show-fields=true?show-fields=false?show-fields=true
after toggling a few times. With :html5? false
it works as expected.
(defn navigate! [view params query]
(debugf "Navigating to: %s" {:view view :params params :query query})
(bide/navigate! router view params query))
(defn toggle-fields-visible! [{:keys [name params query]}]
(navigate! name params (update query :show-fields #(if (= "true" %) "false" "true"))))
The output is:
DEBUG [xxx.core:31] - Navigating to: {:view :xxx/query-table, :params {:table-name "log"}, :query {:show-fields "false"}}
Nice library!
Now that resolve
exists in cljs.core
, the compiler emits a warning:
WARNING: resolve already refers to: cljs.core/resolve being replaced by: bide.core/resolve at line 121 /main.out/bide/core.cljs
Could this be fixed with a quick (:refer-clojure :exclude [resolve])
in bide.core
?
When using the hash parameter setting, bide creates URLs that position the search
(the ?...
fragment) AFTER the hash fragment. In fact, it should be the other way around (see below).
https://superuser.com/questions/498617/does-an-anchor-tag-come-before-the-query-string-or-after
I like the syntax, so why not? I might take a stab at this later on. :)
I'd very much like to use Bide, but can't seem to get it working. Would it be possible to provide an example project using bide to navigate between several simple pages?
Hi!
I have a question about how to best approach this; I'm basically trying to encode redirection data into a route. I thought it would go like this:
;; construct the login route and try to reconstruct the original data
(r/resolve router ::login {} {:redirect [::artist-view {:id 1}]})
;; => "/?redirect=artist-view&redirect=%7B%3Aid%201%7D"
(r/match router *1)
;; => [:user/login nil {:redirect ["artist-view" "{:id 1}"]}]
As you can see the structure of the vector gets destroyed. Can I hook into the encoding somehow? Is there a better approach that I'm not seeing?
The function for navigating, navigate!
, adds a new entry to the history and changes the URL. Would it make sense to have an alternative that doesn't add an entry to the history? Kind of how pushState
and replaceState
work in the History API.
Love the library. Very simple to use. Did run into issues with anchors. if they are on the path then they leak into the produced results.
(def routes [["/" :root] ["/:id" :root-with-id]])
(def my-router (r/router routes))
(r/match my-router "/") ; [:root nil nil]
(r/match my-router "/?a=1") ; [:root nil {:a "1"}]
(r/match my-router "/?a=1#asdf") ; [:root nil {:a "1#asdf"}]
(r/match my-router "/#asdf") ; [:root-with-id {:id "#asdf"} nil]
(r/match my-router "/my-id#asdf") ; [:root-with-id {:id "my-id#asdf"} nil]
(r/match my-router "/my-id?a=1#asdf") ; [:root-with-id {:id "my-id"} {:a "1#asdf"}]
everytime I use navigate! I get the following error entry in the browser console:
TypeError: null is not an object (evaluating '= this.hiddenInput_.value = token') history.js:899
update_ history.js:899
check_ history.js:871
setHistoryState_ history.js:682
setToken history.js:621
(anonymous function) core.js:316
bide$core$_navigare core.js:16
it does not break things, but clutters the console output.
it seems that this 'hiddenInput' thing is specific to goog.History
Is there a reason why bide does not use goog.HTML5History?
Do I need something like pushy for pushState? Or does bide take care of that as well?
First of all: Bide just works! It's great. Thank you!
I'm using shadow-cljs and that means frequent reloads of code.
However, I have to stuck any bide setup code in init (i.e. it only runs once), since it seems there's no stop!
method and setting up another router leads to multiple registration of navigation events (i.e. after 4 re-loads any click on a route is done 4 times).
Would be great to have a stop!
function to cleanup or a way to dynamically add routes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.