# \[7.2-7.3\] Plugin development routes best practices

**URL:** https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967
**Category:** Kibana
**Created:** [October 23, 2019, 9:45pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967 "2019-10-23T21:45:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [October 23, 2019, 9:45pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/1 "2019-10-23T21:45:27Z")

</div>

Hi there!

I'm developing (trying to, actually) a Kibana plugin (already opened couple of threads about it).

Here I wanted to ask you which was the best way to implement routing across the plugin pages.

Let's say in the main page of the plugin I start selecting the index pattern as a link (similar to what happens when selecting the index pattern in the machine learning plugin).

Clicking on the desired index-pattern, I'd like to go on to the next page (let's say to `/category` page), obviously keeping the info about the selected index pattern stored in props.  
Which is the best way to accomplish that? Do I simply use `Router` and `Route` in the Main component or do I have to set something in the `server/` folder?

Thank you

---

<div class="post-metadata">

### Author: ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)
#### Post date: [October 24, 2019, 3:23pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/2 "2019-10-24T15:23:39Z")

</div>

Hey @Fabio-sama! Client-side routing is done a number of ways within Kibana, there isn't really one right way at this point in time. You don't have to put anything in the `server/` folder to accomplish this. Internally, a lot of applications use [React Router](https://reacttraining.com/react-router/). I'd highly recommend staying away from AngularJS's routing. I'd recommend looking at some internal usages of `react-router-dom` for inspiration and precedent.

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [October 24, 2019, 4:06pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/3 "2019-10-24T16:06:59Z")

</div>

Thank you for the reply.

I'm trying with React Router but I'm having some problems.  
Following the video you linked I imported

```
import { BrowserRouter as Router, Route, Link } from 'react-router-dom'

```

Then I wanted to render a EuiInMemoryTable listing all the index-patterns and I wanted to go to the next page of the plugin at the URL #/{index-pattern} (without really seeing the hash # but the url I am at the moment, so `localhost:5603/uif/app/my_plugin/my-index-pattern`)

So I did something like:

```
return (
  <Router>
    <React.Fragment>
      <EuiInMemoryTable
        items={this.state.items}
        loading={this.state.isLoading}
        columns={[
          {
            field: 'label',
            name: this.props.table_title,
            render: (index) => (
              <span>
                <EuiIcon
                  type={this.props.icon_type}
                  size="m"
                  style={{ verticalAlign: 'text-top' }}
                />{' '}
                <EuiLink href={`/uif/app/my_plugin/${index}`} target="_self"> {/* <<<<< HOW CAN I AVOID TO WRITE THE WHOLE URL AND NOT SEE THE # EITHER ? */}
                  {index}
                </EuiLink>
              </span>
            ),
            sortable: true,
            truncateText: true,
          }
        ]}
        search={search}
        pagination={true}
        sorting={true}
      />
      <Route path='/uif/app/my_plugin/:index' component={Test}/>
    </React.Fragment>
  </Router>
);

```

And below I defined the component

```
const Test = () => (
  <div>
    <h1>Test</h1>
  </div>
)

```

When I click on one of the links in the table on the landing (first) page, I would expect to be redirected to a blank page with only a write `Test` in it.  
Instead I get  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2add6038d049de2a2587721e07f4a1d75aec83f2.png)  
Even though the URL is the one I would expect (`http://localhost:5603/uif/app/my_plugin/kibana_sample_data_flights`)

It means I'm not correctly redirecting it to the component I want to show. How can I do that?

Thanks!

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [October 24, 2019, 4:20pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/4 "2019-10-24T16:20:58Z")

</div>

I even tried using the switch (obviously importing it) like

```
return (
  <Router>
    <React.Fragment>
      <EuiInMemoryTable
        items={this.state.items}
        loading={this.state.isLoading}
        columns={[
          {
            field: 'label',
            name: this.props.table_title,
            render: (index) => (
              <span>
                <EuiIcon
                  type={this.props.icon_type}
                  size="m"
                  style={{ verticalAlign: 'text-top' }}
                />{' '}
                <Link to={`/uif/app/my_plugin/${index}`} target="_self">
                  {index}
                </Link>
              </span>
            ),
            sortable: true,
            truncateText: true,
          }
        ]}
        search={search}
        pagination={true}
        sorting={true}
      />
      <Switch>
        <Route path="/uif/app/my_plugin/kibana_sample_data_flights">
          <Test />
        </Route>
      </Switch>
    </React.Fragment>
  </Router>
);

```

And here I tried defining the functional component Test.js and importing it, rather than using `const` below the code.

Same `404` error.

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [October 30, 2019, 2:14pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/5 "2019-10-30T14:14:18Z")

</div>

Sorry to bother you, but can't you help me further?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 27, 2019, 2:14pm UTC](https://discuss.elastic.co/t/7-2-7-3-plugin-development-routes-best-practices/204967/6 "2019-11-27T14:14:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
