Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Default Route in ui-router-react #36

Closed
mfreeman-xtivia opened this issue Mar 26, 2017 · 1 comment
Closed

Setting Default Route in ui-router-react #36

mfreeman-xtivia opened this issue Mar 26, 2017 · 1 comment

Comments

@mfreeman-xtivia
Copy link

mfreeman-xtivia commented Mar 26, 2017

How does one go about defining a default landing route in ui-router-react, ie the state you wish to navigate to on something like http://localhost:8080?

When using ui-router-ng2 I did something like this....

let homeState  = { name: 'home',  url: '',       component: TaskListComponent }; 
let tasksState = { name: 'tasks', url: '/tasks22',  component: TaskListComponent }; 
let aboutState = { name: 'about', url: '/about22',  component: AboutComponent };
UIRouterModule.forRoot({ states: [ homeState, tasksState, aboutState ], useHash: true })

which triggers navigation to the home state on the default landing. I tried to something equivalent in ui-router-react by using the following

var app_states = [
  {name: "home",  url: '',           component: UserList },
  {name: "users", url: "/userList",  component: UserList },
  {name: "todos", url: "/todoList",  component: TodoList }
];
ReactDOM.render(
   <UIRouter plugins={[pushStateLocationPlugin]} states={app_states} >
    <div>
      <UISrefActive class="active"><UISref to="users"><a>Users</a></UISref></UISrefActive>
      <UISrefActive class="active"><UISref to="todos"><a>ToDos</a></UISref></UISrefActive>
      <UIView/>
    </div>
  </UIRouter>,
  document.getElementById('app')
);

but it doesn't seem to work the same, ie upon navigating to http://localhost:8080 the react router doesnt't navigate to the home state as I expected it--it does nothing but display the nav panel (which works fine when i start clicking on linkds)

Is there some way to effect the equivalent default state in the react version of ui-router?

@mfreeman-xtivia
Copy link
Author

NM. Just needed to switch to use hashLocationPlugin instead of pushStateLocationPlugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant