kriasoft / universal-router

A simple middleware-style router for isomorphic JavaScript web apps
https://www.kriasoft.com/universal-router/
MIT License
1.7k stars 104 forks source link

How to create REST routes on SB Admin React Starter Kit #66

Open daniramdani opened 7 years ago

daniramdani commented 7 years ago

Hi koistya, I'm newbie in React JS, I'm using SB Admin React Starter Kit to create my app, I wish to create kind REST routes :

http://example.com/users http://example.com/users/1 http://example.com/users/create http://example.com/users/add

But I can't figure out how to make it, may you can help me to solve my problem ?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/38907533-how-to-create-rest-routes-on-sb-admin-react-starter-kit?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github).
frenzzy commented 7 years ago
import { resolve } from 'universal-router'

const routes = {
  path: '/users',
  children: [
    { path: '/', action() { return 'Users' } },
    { path: '/create', action() { return 'Create User' } },
    { path: '/add', action() { return 'Add User' } },
    { path: '/:id', action(context) { return `User #${context.params.id}` } },
  ]
}

resolve(routes, '/users/1').then(result => {
  document.body.innerHTML = result
})

Playground: https://jsfiddle.net/frenzzy/pg0ouyxm/

daniramdani commented 7 years ago

Hi frenzzy,

Thanks for your response, how to implemet with SB Admin React Starter Kit ?

Thanks

frenzzy commented 7 years ago

Add by analogy with other routes