GithubHelp home page GithubHelp logo

Comments (16)

ohNegative avatar ohNegative commented on May 2, 2024 1

@koistya quick question: the folder structure is obvious, but I can't seem to get the router to go to the blog index page: http://localhost:3000/blog/ or http://localhost:3000/blog/index but the router is working fine for the two article pages: http://localhost:3000/blog/test-article-one

Is there something I'm missing?

Thanks,

P

from react-firebase-starter.

Metis77 avatar Metis77 commented on May 2, 2024

+1

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

Inside the app.js file there is a hash table with routes in a form of a plain JavaScript object:

const routes = {};

During a build it is filled with routes based on the list of *.js files in the src folder. So that if you have /src/about.js and /src/404.js files for example, it will generate the following routes:

const routes = {
  '/404', () => new Promise(resolve => require(['./404.js'], resolve),
  '/about', () => new Promise(resolve => require(['./about.js'], resolve)
};

It uses webpack's code splitting feature to load missing components at run-time.

Then, when application loads into a browser, it extracts a route handler from that object given a URL path and executes it:

const action = routes[window.location.pathname] || routes['/404'];
const component = await action();
React.render(React.createElement(component), document.body);

Hope this helps :)

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

image

from react-firebase-starter.

westn avatar westn commented on May 2, 2024

How does the navigation-link look like?
Is it so that I can navigate to "http://localhost:3000/#about" or "http://localhost:3000/about", I can't seem to get any of them to work.

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

When you a regular navigation link such as <a href="/about">About</a> this links needs to have a click handler which redirects a client to a new page without full page refresh and prevents the default behaviour (event.preventDefault()). I will try to create an example how you can do it..

from react-firebase-starter.

Metis77 avatar Metis77 commented on May 2, 2024

I'd love to have an tutorial, too.

from react-firebase-starter.

philkeys avatar philkeys commented on May 2, 2024

@koistya

With this routing system, is there a way to have a route, when activated, put the user at the top of the page? I've found that if I click on a link halfway down a screen, then the new view has the same placement.

Any help would be greatly appreciated.

from react-firebase-starter.

 avatar commented on May 2, 2024

The routes do not work if the compiled/build folder is made to run on a non-nodeJS based server like Apache or WAMP. Only the page at the root '/' loads in a non-node serve. Is there a node server dependency for the routes to work?
Could you advice on how to fix this to make the routes work on a non node server?

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

@vineesv you may want to change the pages build step, so that it generates index.html for each route. E.g. instead of /about.html you need to have /about/index.html.

from react-firebase-starter.

ohNegative avatar ohNegative commented on May 2, 2024

@philkeys have you tried this yet: https://www.npmjs.com/package/react-scroll

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

It seems like BrowserSync doesn't understand that '/blog/index.html' should be accessed via '/blog' URL. I guess, it might be a good idea to generate /blog.html instead of /blog/index.html inside the build (dist) folder.

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

Here is the logic that generates .html file names from React routes:

https://github.com/koistya/react-static-boilerplate/blob/master/utils/routes-loader.js

from react-firebase-starter.

ohNegative avatar ohNegative commented on May 2, 2024

@koistya thanks for the heads up - I'll try that!

from react-firebase-starter.

n8sabes avatar n8sabes commented on May 2, 2024

We need to locate the root of the site one level below the domain name, however the compilation process crashes when you include a path in routes-loader. We need:

http://domain.com/v1/index.html

How can this be done?

from react-firebase-starter.

koistya avatar koistya commented on May 2, 2024

@n8sabes I have refactored the routing, do you think it covers your use case? Check it out:

https://github.com/kriasoft/react-static-boilerplate/blob/master/docs/routing-and-navigation.md

If not, please don't hesitate to contact me with some more info about your scenario.

from react-firebase-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.