Giter Club home page Giter Club logo

Comments (10)

fisshy avatar fisshy commented on September 25, 2024

good point, but doesn't react-router repaint the view when you navigate to a new URL?

Or are you keeping all the sections under /mypage and using "section1" as param?

This feature should be added, gotta figure out a nice way to integrate it with react-router.

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

All sections are under /mypage and section1 is a param. I have this currently working with react-router, just not the "scroll to section on page load" portion.

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

Here's what the route looks like.

<Route name='mypage' path='/mypage/?/:section?' handler={MyPage}/>

from react-scroll.

chiefjester avatar chiefjester commented on September 25, 2024

@fisshy so what's the final api here? How do you scroll by id pragmatically?

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

@deezahyn This is how we are doing it.

import React from 'react';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';

import { scroller, scrollSpy } from 'react-scroll';

class ComponentsPage extends React.Component {

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    let params = this.context.router.getCurrentParams();
    if (params.section && params.section.length > 0) {
      scroller.scrollTo(params.section, false, 0, -65);
    }
  }

  componentWillUnmount() {
    scrollSpy.unmount();
    scroller.unmount();
  }

  render() {
    return (
      <Row>
        <Col md={10}>
          <div>Components here</div>
        </Col>
      </Row>
    );
  }
}

ComponentsPage.contextTypes = {
  router: React.PropTypes.func.isRequired
};

export default ComponentsPage;

from react-scroll.

chiefjester avatar chiefjester commented on September 25, 2024

what's the param section? is that a string? or DOM? Say I can access the actual dom via refs. this.refs.myBox. How would I go about scrolling to that parameter?

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

@deezahyn Have a look at the example. You use <Element name='myLink'> and <Link to='myLink'>. The Link scrolls to the item defined by Element when it is clicked. If you want to manually do it yourself, outside of the Link (such as on Page Load, which is what the issue is you are posting on), you can use the scroller as I posted above. You still use Element to define the sections that can be scrolled to. You don't work with DOM elements directly.

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

This is how Element knows what to scroll to.

from react-scroll.

chiefjester avatar chiefjester commented on September 25, 2024

it says target Element not found

from react-scroll.

joemcbride avatar joemcbride commented on September 25, 2024

@deezahyn Please open a new issue and post the code you're having trouble with.

from react-scroll.

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.