Backbone.js with Rails routing - ruby-on-rails-4

I have backbone view that navigates url to localhost:3000/about but when i do realod page, Rails routing takes care of routing and redirects me to rails page, not Backbone view. I was reading some tutorials about backbone routing, for example: http://www.codeproject.com/Articles/803073/BackBone-Tutorial-Part-Understanding-Backbone-js-R but anything i do, it doesn't work. Is it even possible to route page after reload to correct backbone view, as it is easy for Rails?

It is normal. When the route is hit, your backend router will fetch and return the corresponding rails view if the router is configured to do so.
When the page is loaded into the browser, only at this moment the backbone router should be instantiated.
By default, Backbone uses hashtags# to route, but by instantiating the router with pushstate:true, you can fetch templates from the backend without losing front end state in your application.

Related

Using Browser Router in react-router-dom with Django backend

I'm building an application that uses React as front-end and Django Rest as back-end.
From front-end, I'm using react-router-dom for declarative routing and Django only serves API
So when user enters an URL like this https://myapp.com/something/something-else, it's actually handle by Django and it will return an error since Django doesn't know which page to lead to with this URL. It should be handled by React instead.
One of the workaround I have is to use a Hash Router, so the URL will look like this (with the hash symbol): https://myapp.com/#/something/something-else
But there have been cases where user will just key the URL without the hash sign (as they didn't know).
Is there away to handle this without using Hash Router?
I can't say exactly because you haven't provided code, or an explanation of your project structure.
How are you doing a hash-router? If you have Django serving a single HTML file, then you should be able to edit your urls.py to pass any URLs that don't match the api to the same page.
As an example, I have a Django website with a Preact frontend, and I have Preact files that are built into static .js files, which are then served by Apache. Django does all URL routing and serves HTML files, which then request the Preact JS files from Apache.

Django Authentication and ReactJS Templates

I have an existing login template served by django templates and it has no react components at all. I have recently integrated ReactJS and have created some routes and components and pages that are completely react. Now I am wondering how to get a user to login through the django template and then be redirected to the ReactJS page afterwards and pass on all the authentication/user information to ReactJS as well.
In Django, I am using the session authentication middleware.
I have done that just allowing an open url to my component something like ".../app/*". But this inside a template in Django as a bundle. What I do is to bind the view with that with LogginRequired from django-brases. So, if I want to se my app, I have to be authenticated. I hope this could help you.

How to use react-router and Django templates

Folks,
I am pretty sure I am not the first one to stumble on this problem. But somehow I am unable to find any relevant resources out there.
Here is my issue, I have a backend in Django and my front completely written in Reactjs- React Router - Redux (nice combo right).
when entering the url webhost.com/, django provides me with a page with links to a bundle that is my whole react application and different stylesheets
The problem arise when I want to refresh a page, the browser still tries to query the server even though a route exists in my react-router configuration.
I had a look at the answer here (catch-all option) React-router urls don't work when refreshing or writting manually , but I don't quite understand it and I am afraid to have a new redux state everytime Django will provide the user with a new page.
You can setup up a wildcard url pattern that will render the same view that gets rendered when a request is sent to webhost.com. I don't know if that's going to retain your store though.

Lookup route from URL in Ember router

The Ember router creates a URL from a route, e.g. with the link-to helper. Is it possible to reverse-lookup a route from a given URL?
The reason for this is that I have some absolute URL links in my database which point to pages in my Ember app, and I want to transition to them within the app. Using <a href={{link}}> works, but breaks my tests (when running ember test -s) as following the link redirects the whole browser page, stopping the test suite. If it's possible to redirect to an absolute URL without breaking the test suite that would also do the trick.

Replace, not append to, the site's body content in Ember.js

I had the following idea: my page at example.org serves classic HTML from the server. Besides, EmberJS is loaded, too, and waiting to come into action:
as soon as somebody hits an ember route then, for example example.org/#/login, the current should be replaced by what the view renders for it. From then, the whole app should serve as one-page-app.
Is that a good idea? Anyway, I don't know how to get that started. Overriding View's appendTo method or setting the rootElement property as in http://emberjs.com/guides/configuring-ember/embedding-applications/ does not suffice because if that were the body, the view output is just appended thereā€¦
If your entire Ember application requires a user to be logged in, it is valid to have two separate "apps":
A regular non single-page application (server-side using rails, PHP or C#) with a sign up and login pages
A single-page application (i.e. Ember) send as soon as the user hits the login button in your regular app
You will have 2 index.html pages, one for each application (and it's okay to do that!). The URL of the Ember App could be under example.org/app/.... You will need to configure the router of the regular application to server your Ember App for all URLs starting with /app/.
Does that help? :)