Skip to content

How to handle path="" route #230

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

Closed
xeodou opened this issue Aug 26, 2014 · 14 comments · Fixed by #237
Closed

How to handle path="" route #230

xeodou opened this issue Aug 26, 2014 · 14 comments · Fixed by #237

Comments

@xeodou
Copy link

xeodou commented Aug 26, 2014

I use the router like this

 <Routes>
        <Route name='app' handler={App}>
            <DefaultRoute handler={Home} />
            <Route name='home' path='/' handler={Home} />
            <Route name='repo' path='/repo' handler={Repo}/>
        </Route>
    </Routes>

When i call http://127.0.0.1:3000/# without / after # will get some warning like this
No route matches path "". Make sure you have <Route path=""> somewhere in your routes
How can i handle this . I see you guys talking about #221 #140 , I want to ask how can i handle this for now ?

@ryanflorence
Copy link
Member

  <Routes>

        <!-- defaults to path="/" -->
        <Route name='app' handler={App}>

            <!-- is the default handler for `App`, so path="/" -->
            <DefaultRoute handler={Home} />

            <!-- conflicts with DefaultRoute -->
            <Route name='home' path='/' handler={Home} />

            <Route name='repo' path='/repo' handler={Repo}/>
        </Route>
    </Routes>

Try this:

<Routes>
    <Route name='app' handler={App}>
        <DefaultRoute handler={Home} />
        <Route name='repo' path='/repo' handler={Repo}/>
    </Route>
</Routes>

@ryanflorence
Copy link
Member

Let me know if that doesn't work, and I'll reopen.

@xeodou
Copy link
Author

xeodou commented Aug 26, 2014

I have already try this before if use

<Routes>
    <Route name='app' handler={App}>
        <DefaultRoute handler={Home} />
        <Route name='repo' path='/repo' handler={Repo}/>
    </Route>
</Routes>

will get these warning

Warning: No route matches path "/". Make sure you have <Route path="/"> somewhere in your routes warning.js:44
Warning: No route matches path "". Make sure you have <Route path=""> somewhere in your routes 

@ryanflorence
Copy link
Member

Oh, right, either remove the name from "app" or add the path "/" to it.
Paths are implied from names, so its looking for "app"
On Aug 25, 2014 11:59 PM, "xeodou" [email protected] wrote:

I have already try this before if use

will get these warning

Warning: No route matches path "/". Make sure you have somewhere in your routes warning.js:44
Warning: No route matches path "". Make sure you have somewhere in your routes


Reply to this email directly or view it on GitHub
#230 (comment).

@xeodou
Copy link
Author

xeodou commented Aug 26, 2014

I change my route to this

 <Routes>
        <Route path='/' handler={App}>
            <DefaultRoute handler={Home} />
            <Route name='repo' path='/repo' handler={Repo}/>
        </Route>
    </Routes>

It's very strange ,when i call http://127.0.0.1:3000/#, first time I see Warning: No route matches path "". Make sure you have <Route path=""> somewhere in your routes in the console panel, then i re-click the enter key in the address bar , it works fine. I try several times got the same result.

@natelaws
Copy link

Yeah, I get the same warning.

var Anything = React.createClass({
   render: function() {
       console.log("anything");
       return (<div>Hi</div>);
   }
});

var App = React.createClass({
    render: function () {
        console.log("app");
        return (this.props.activeRouteHandler());
    }
});

React.renderComponent(
    <Routes>
        <Route handler={App}>
            <DefaultRoute handler={Anything} />
            <Route path="/foo" handler={Anything} />
        </Route>
    </Routes>,
    document.getElementById('app')
);

The only ones that work are localhost/#/ and localhost/#/foo. How do I get localhost/# and localhost/#asdf to work (Note the missing slash).

@ryanflorence
Copy link
Member

Try this:

React.renderComponent(
    <Routes>
        <Route handler={App}>
            <DefaultRoute handler={Anything} />
            <Route path="/foo" handler={Anything} />
        </Route>
        <Route path="*" handler={NotFound}/>
    </Routes>,
    document.getElementById('app')
);

@natelaws
Copy link

Yep, I tried the path="*" thing too.

The path="*" is only matching when its /#/something instead of just /#something... Basically it looks like like / after the hash is required for any route to match, otherwise we get the warning and no component rendered.

@ryanflorence
Copy link
Member

The only way this can happen is if the user types in that url. We should
handle that and add the slash
On Aug 26, 2014 5:14 PM, "Nate Laws" [email protected] wrote:

Yep, I tried the path="*" thing too.

The path="*" is only matching when its /#/something instead of just
/#something... Basically it looks like like / after the hash is required
for any route to match, otherwise we get the warning and no component
rendered.


Reply to this email directly or view it on GitHub
#230 (comment).

@bobeagan
Copy link
Contributor

Can someone edit the title of this issue to fix the paht typo? My OCD starts twitching like mad every time I get a notification for this.

@sophiebits sophiebits changed the title How to handle paht="" route How to handle path="" route Aug 26, 2014
@natelaws
Copy link

For what it's worth, this can also easily happen if some <a href="#"> sneak in. Can this issue be reopened or should a new issue be created?

@ryanflorence ryanflorence reopened this Aug 27, 2014
@ryanflorence ryanflorence changed the title How to handle path="" route How to handle hash location routes without the preceding slash Aug 27, 2014
@ryanflorence ryanflorence changed the title How to handle hash location routes without the preceding slash How to handle path="" route Aug 27, 2014
@xeodou
Copy link
Author

xeodou commented Aug 28, 2014

Does it will release in version 0.5.4 ?

@ryanflorence
Copy link
Member

yeah, today or tomorrow, soon as I can document some of the other changes

@xeodou
Copy link
Author

xeodou commented Aug 28, 2014

OK, Thanks.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants